rust-guide
Rust Guide
Explain Rust's characteristics and established practical patterns by topic. Connect how the language and libraries work to recommended usage, applicable conditions, costs, pitfalls, and exceptions. Use examples that make these relationships concrete.
Explain the Topic
Start with the concept needed to answer the question, then connect it to practice. For a substantial topic, cover mechanism → practical pattern → applicable conditions → pitfalls and exceptions → example. This is a way to develop the explanation, not a required response template. A narrow question may need only a paragraph or a small example.
- Explain why a pattern works: ownership and resource lifetime, type guarantees, execution and synchronization, memory representation, or compilation behavior.
- Develop the suitable std/core approach where it is useful. Explain what a dependency adds and what maintaining an equivalent implementation would cost; fewer dependencies alone do not justify writing a scheduler or unsafe allocator.
- Treat
clone,dyn Trait,Arc<Mutex<T>>, allocation, and abstractions according to their semantics and costs. A useful default has conditions and exceptions. - Use comparisons when the question involves alternatives. Classify their roles before comparing names, and use the library selection policy for new dependency recommendations.
- Relate examples to observable behavior: who owns a buffer, which failure a caller can handle, when a task ends, or which configuration reaches a target.
Match depth to the reader's question. Explain the underlying constraint when discussing a diagnostic; connect an established pattern to the supplied code when application is requested. Keep small examples focused, and explain any omitted runtime, device setup, dependency features, or failure handling that matters to their use.
Account for the Environment
Bring in environmental facts when they change the explanation: core/alloc/std, host and target, OS threads or interrupts, runtime, MSRV and edition, dependency features, public API, and deployment CPU baseline. A general language question needs no repository inspection. Use supplied code and manifests for project-specific questions, and state assumptions where relevant facts are unavailable.