External References
- Microsoft Rust Guidelines: https://microsoft.github.io/rust-guidelines
- Rust API Guidelines: https://rust-lang.github.io/api-guidelines/
Universal Guidelines (Must Follow)
These guidelines from the Microsoft Rust Guidelines are particularly important for BoxLite:Safety Guidelines
BoxLite-Specific Patterns
Async-First Architecture
All I/O operations use async/await with Tokio runtime:Centralized Error Handling
Use theBoxliteError enum for all errors (see boxlite-shared/src/errors.rs):
Public Types Must Be Send + Sync
All public types exposed through the API must be thread-safe:
Formatting and Linting
- Formatting:
cargo fmt(enforced in CI) - Linting:
cargo clippy(warnings are errors in CI)
Quick Reference
When writing Rust code for BoxLite, ask yourself:Is this panic necessary? (M-PANIC-ON-BUG)
Is this panic necessary? (M-PANIC-ON-BUG)
Only panic on programming errors (bugs). Use
Result for all expected failures such as I/O errors, invalid input, or network issues.Is this name clear? (M-CONCISE-NAMES)
Is this name clear? (M-CONCISE-NAMES)
Avoid vague weasel words like “Manager”, “Service”, and “Factory”. Choose names that describe what the type actually does.
Is this unsafe minimized? (M-UNSAFE)
Is this unsafe minimized? (M-UNSAFE)
Isolate and document all unsafe code in small, focused functions. Every unsafe block must explain why it is sound.
Does this implement Debug? (M-PUBLIC-DEBUG)
Does this implement Debug? (M-PUBLIC-DEBUG)
All public types must implement
Debug. User-facing types should also implement Display.Is this async? (Async-First)
Is this async? (Async-First)
All I/O operations should be async using Tokio. Never use blocking I/O inside an async context.
Is the error contextual? (Centralized Errors)
Is the error contextual? (Centralized Errors)
Use
BoxliteError with descriptive messages. Every error should explain what went wrong and where.
