协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
rust-domain-boundaries【开发与工程】Use when modeling, validating, refactoring, or reviewing Rust service domain boundaries, especially when replacing primitive String fields with newtypes, parse-don't-validate constructors, private invariants, TryFrom/FromStr parsers, request DTO boundaries, or property tests.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Use this skill to keep invalid states out of Rust service internals. Parse raw input once at the boundary, store validated values in narrow domain types, and make unchecked construction difficult.
serde deserialize incoming
shapes, then convert DTO fields into validated domain values.pub fields or impl From<String> for fallible conversions.TryFrom<String>, TryFrom<&str>, or FromStr for fallible parsing.AsRef<str> or a named accessor for read-only exposure.Display only when the formatted value is safe to show in logs,
errors, and UI.Debug for secret-bearing values unless the debug output is
redacted.Deserialize into a request shape, then construct a command:
#[derive(serde::Deserialize)]
pub struct SubscribeRequest {
email: String,
name: String,
}
pub struct SubscribeCommand {
pub email: EmailAddress,
pub name: SubscriberName,
}
impl TryFrom<SubscribeRequest> for SubscribeCommand {
type Error = SubscribeValidationError;
fn try_from(value: SubscribeRequest) -> Result<Self, Self::Error> {
Ok(Self {
email: EmailAddress::parse(value.email)?,
name: SubscriberName::parse(value.name)?,
})
}
}
Handlers should reject invalid input before business logic or database code. If validation needs database state, keep pure parsing separate from uniqueness or authorization checks.
Read references/property-testing.md when invariants have many edge cases or
when an AI agent is likely to miss invalid inputs with example-only tests.
Minimum tests for a new domain type:
serde or SQL mapping when that type crosses those
boundaries.references/newtype-patterns.md: constructor, trait, serde, and persistence
patterns for Rust newtypes.references/property-testing.md: property-testing strategy for parsers and
domain constructors.