neo-rust
Installation
SKILL.md
Neo Rust Expert
Write safe, maintainable, and idiomatic Rust code by strictly following the official design patterns, leveraging Rust's powerful type system, and avoiding anti-patterns.
Gotchas
- Gotcha 1 (Async Mutex Deadlock / Send Error):
In an
asyncfunction, using the standard library'sstd::sync::Mutexand holding itsMutexGuardacross an.awaitboundary will cause a compiler error becauseMutexGuarddoes not implementSendand cannot be transferred across threads.- Solution: Use a local block
{}to limit the MutexGuard lifetime before the.await, or usetokio::sync::Mutexinstead.
- Solution: Use a local block
- Gotcha 2 (Excessive Cloning):
To satisfy the Borrow Checker, beginners often call
.clone()excessively, which introduces significant memory allocation and copy overhead.- Solution: Prioritize passing borrowed references (e.g.,
&strinstead ofString,&[T]instead ofVec<T>), or refactor ownership structures and lifetimes.
- Solution: Prioritize passing borrowed references (e.g.,
- Gotcha 3 (Unsafe Unwrapping):
Using
.unwrap()orpanic!()directly in library or production-grade code will cause the application to crash, violating Rust's safety-first principle.- Solution: Always return
Result<T, E>orOption<T>for graceful error propagation, and use the?operator ormatchexpression to handle them.
- Solution: Always return