skills/rust-api-design/SKILL.md
Rust API 設計模式。用於 Builder Pattern、Newtype、型別安全設計、trait 設計、泛型 API、Sealed traits。
npx skillsauth add vincent119/ai-rules-kit rust-api-designInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
#[derive(Debug, Clone)]
pub struct ServerConfig {
host: String,
port: u16,
max_connections: usize,
}
#[derive(Debug, Default)]
pub struct ServerConfigBuilder {
host: Option<String>,
port: Option<u16>,
max_connections: Option<usize>,
}
impl ServerConfigBuilder {
pub fn host(mut self, host: impl Into<String>) -> Self {
self.host = Some(host.into());
self
}
pub fn port(mut self, port: u16) -> Self {
self.port = Some(port);
self
}
pub fn max_connections(mut self, max: usize) -> Self {
self.max_connections = Some(max);
self
}
pub fn build(self) -> Result<ServerConfig, ConfigError> {
Ok(ServerConfig {
host: self.host.unwrap_or_else(|| "localhost".into()),
port: self.port.unwrap_or(8080),
max_connections: self.max_connections.unwrap_or(100),
})
}
}
impl ServerConfig {
pub fn builder() -> ServerConfigBuilder {
ServerConfigBuilder::default()
}
}
/// 用 Newtype 區分語意相同但用途不同的型別
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct UserId(String);
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct OrderId(String);
impl UserId {
pub fn new(id: impl Into<String>) -> Self {
Self(id.into())
}
pub fn as_str(&self) -> &str {
&self.0
}
}
// 錯誤:bool 參數語意不明
fn connect(host: &str, use_tls: bool) {}
// 正確:使用具名型別
pub enum Transport {
Plain,
Tls,
}
fn connect(host: &str, transport: Transport) {}
// 接受 &str、String、PathBuf 等
pub fn read_file(path: impl AsRef<std::path::Path>) -> std::io::Result<String> {
std::fs::read_to_string(path)
}
mod private {
pub trait Sealed {}
}
/// 外部 crate 無法實作此 trait
pub trait MyTrait: private::Sealed {
fn do_something(&self);
}
impl private::Sealed for MyType {}
impl MyTrait for MyType {
fn do_something(&self) { /* ... */ }
}
/// Service 型別應可 Clone(內部用 Arc 共享狀態)
#[derive(Debug, Clone)]
pub struct UserService {
db: Arc<DatabasePool>,
cache: Arc<RedisClient>,
}
new()bool/Option 參數;用 enum 表達意圖impl AsRef<T> / impl Into<T> 提升彈性Clone(內部 Arc 共享)tools
基於 SLA/SLO 量化評估事故影響的計算模型與業務影響矩陣。適用於「SLA 影響」、「SLO 違反」、「影響評估」、「營收損失估算」、「Error Budget」、「可用性計算」、「事故成本評估」等量化事故業務影響的任務。強化 impact-assessor 的評估能力。注意:事故原因分析與改善規劃不在此技能範圍內。
research
根因分析(RCA)方法論詳細指南。提供 5 Whys、Fishbone 圖、Fault Tree Analysis、變更分析等結構化 RCA 技術,以及認知偏誤防範清單。適用於「根因分析」、「RCA」、「5 Whys」、「魚骨圖」、「Fault Tree」、「原因分析方法論」、「變更分析」等事故原因分析任務。強化 root-cause-investigator 的分析能力。注意:時間軸重建與改善規劃不在此技能範圍內。
testing
事故事後分析(Postmortem)完整流程。協調 7 個執行階段:資訊收集 → 時間軸重建 → 根因分析 → 影響評估 → 改善規劃 → 報告審查 → 整合報告,最終產出完整的 Postmortem 報告。適用於「寫事故報告」、「post-incident 分析」、「RCA 報告」、「事故時間軸整理」、「建立改善措施」等請求。注意:即時 Incident Response(on-call)、監控系統設定、告警配置不在此技能範圍內。
content-media
投影片版面模式庫。提供 20 種投影片類型的最佳版面配置、格線系統、色彩與字型設計 Token。適用於「投影片版面」、「Slide Layout」、「設計系統」、「格線」、「字型」、「色彩規範」等投影片視覺設計任務。強化 visual-designer 的設計能力。注意:PPT/Keynote 檔案直接輸出不在此技能範圍內。