Rust has a unique ownership model that allows it to guranee memory safety and
run without a garbage collector.
From all the programming languages I've come across, rust defenitely has its unique feel to it and requires a different way of thinking.
It has also made me explore design patterns other than OOP (which is taught extensively in schools and colleges)
Highly recommend it if you are interested in high performance or low level languages. Also check it out if you are into high level programming because rust can be quite friendly once you get used to it.
- Rust API Guidelines A nice set of tips on how to design your APIs in rust
- A reddit discussion on what Cell and RefCell does
- Rust journey to async/await: A cool talk by Steve Klabnik, where he nicely presented the problems faced and their solutions to designing rust's async/await.
as_ref() has the signature
&Option<T> -> Option<&T>
it turns a reference to an Option into an Option that holds a reference
if we siply try to do
opt.unwrap(); with a reference to an option,
it will complain that it cannot mov out of borrowed content.
We only have a reference to the
Option. unwrapping tries to move the value
inside to option out of it. which is not possible with shared references.
When writing a library, Its common to implement the
for the standard library
Error type. This allows us to use
with a custom error type that implements
std::error::Error. This enables the
users of our library to use our error type, the same way they use the standard
But writing all the implementations can get boring and often quite repetitive. thiserror is a crate that provides a convinient macro to derive the
std::error::Error trait for our custom error
When writin a binary, using anyhow gives us
some nice convinience traits that is implemented for return types like the
context() method: which allows us to add custom error messages when our
application returns an error. It also provides an
Error type that, when used
in the main function, automatically formats the errors nicely to stdout