- Prioritize code correctness and clarity. Speed and efficiency are secondary priorities unless otherwise specified.
- Do not write organizational or comments that summarize the code. Comments should only be written in order to explain "why" the code is written in some way in the case there is a reason that is tricky / non-obvious.
- Prefer implementing functionality in existing files unless it is a new logical component. Avoid creating many small files.
- Avoid using functions that panic like
unwrap(), instead use mechanisms like?to propagate errors. - Be careful with operations like indexing which may panic if the indexes are out of bounds.
- Never silently discard errors with
let _ =on fallible operations. Always handle errors appropriately:- Propagate errors with
?when the calling function should handle them - Use
.log_err()or similar when you need to ignore errors but want visibility - Use explicit error handling with
matchorif let Err(...)when you need custom logic - Example: avoid
let _ = client.request(...).await?;- useclient.request(...).await?;instead
- Propagate errors with
- When implementing async operations that may fail, ensure errors propagate to the UI layer so users get meaningful feedback.
- Never create files with
mod.rspaths - prefersrc/some_module.rsinstead ofsrc/some_module/mod.rs. - When creating new crates, prefer specifying the library root path in
Cargo.tomlusing[lib] path = "...rs"instead of the defaultlib.rs, to maintain consistent and descriptive naming (e.g.,gpui.rsormain.rs). - Avoid creative additions unless explicitly requested
- Use full words for variable names (no abbreviations like "q" for "queue")
- Use variable shadowing to scope clones in async contexts for clarity, minimizing the lifetime of borrowed references.
Example:
executor.spawn({ let task_ran = task_ran.clone(); async move { *task_ran.borrow_mut() = true; } });