350 private links
How Rust differs compared to other programming languages and why it's efficient.
- Indexing into a vector: prefer better pattern matching or raw array with index safety instead
- Lazy use of
Default: initialize all fields instead - Avoid fragile trait implementations that pass silently on changes
Fromtraits must be infaillible, useTryFromif any error can occur. Make it explicit.- Avoid non-exchaustive matches (with
_ =>) - Use decriptive names for unused variables with the
_placeholder. - Avoid temporary mutability and make it explicit instead:
let mut data = ....; .... ; let data = data - Defensively handle constructors with
#[non_exhaustive], so creating an raw instance of a struct should be prohibited outside constructor functions. - Use
#[must_use]to avoid unused instance of the struct. - Avoid boolean parameters and in case of need, prefer enums.
- Use Clippy lints:
- clippy::indexing_slicing
- clippy::fallible_impl_from
- clippy::wildcard_enum_match_arm
- clippy::unneeded_field_pattern
- clippy::fn_params_execussive_bools
The new minor version make the tools faster.
The Rust-Coreutils v0.3.0 supports 83.91% of the GNU Coreutils 9.8.
It's a decreased compared to the 87.06% of the GNU coreutils 9.7.
Wrapping every string to a newtype ensure the string can be extended as wished and at least differenciated from normal strings without meaning
The project: https://github.com/kustomzone/sierra-db
You benchmark your node/ruby/python software on a fancy Macbook M4 and celebrate 500ms response time.
I benchmark my rust software on a $30 potato computer that may as well have 256MB of RAM and celebrate 800ms response time.
Documentation: https://pingoo.io/
Developed by Silvain Kerkour: https://kerkour.com/
The heap is a performance killer in Rust. One woraround is to swap to a more efficient memory allocator such as jemalloc.
In Cargo.toml:
[dependencies]
mimalloc = "0.1"
In main.rs:
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
The best performance optimisation is to avoid the heap. There is the heapless create for that. "The only thing to know is that the size of heapless types and collections needs to be known at compile-time."
Lifetime annotations are needed to tell the compiler that we are manipulating some kind of long-lived reference and let it assert that we are not going to screw ourselves
The only downside is that smart pointers, in Rust, are a little bit verbose (but still way less ugly than lifetime annotations). [They add some runtime overhead.]
When to use lifetimes annotations?
When performance really matters or when your code will be used in no_std environments.
I don't know. It seems to be overkill for the use. Instead of words, some functions get a capital letter.
A work to use rust build as PHP extension
It marks the function as never returning.
In comparison, the unit type () returns at least a value.