Miscellaneous Rust
Programming Tips in Rust
Syntax
Restrict function access to a module scope | |
---|---|
Printing
You can center and pad strings in Rust using the following formatting syntax:
{:#^10}
Example:
Printing a padded String | |
---|---|
Box
You can leak memory using Box::leak
. This is useful when you want to instantiate something on the heap and know it's going to stick around for the lifetime of the application. This means you can get a 'static
lifetime reference to the object and don't have to worry about the cost of deallocating the object during runtime.
Example:
Consume and Leak a Box | |
---|---|
See: Box::leak
Guides, Courses, and Books
Books
Frameworks
Web Frameworks
Example Code
The following resources are good examples of code written in Rust, or are samples of real world applications (no emphasis on good or bad here).
- Real World Axum and Sqlx
- TCPProxy
This is a good example of async network code.
Other Links
- How do I start
- Everything I know (Rust)
- Are We Yet?
- Awesome Rust
- Rust CI Release Template
- David Tolnay writes good Rust #anyhow-author #thiserror-author
- Idiomatic Rust
- Aquascope Playgroud
This is a cool tool that shows you things about your code.
- Rust Cookbook
- Idiomatic Rust
This repository collects resources for writing clean, idiomatic Rust code.
Tools
Sites, Blogs, and Newsletters
- Aweesome Rust Repo Stats
This cool site shows the stats of the most starred and active Rust repositories on GitHub. It's a great way to find out what's popular in the Rust community.
Debugging Tools
Cargo tools
Testing
- Home - cargo-nextest
Test runner