Did you know that you can add doc aliases to your #Rust items (struct, method etc.), so that they appear in #RustDoc search results, when searching for that alias?๐Ÿ”

https://doc.rust-lang.org/rustdoc/advanced-features.html#add-aliases-for-an-item-in-documentation-search

You can even add multiple aliases at once, like this:

#[doc(alias("modify", "index"))]
pub fn modified_field_indices(...);

Such a useful feature (that should be used more often)!

โš ๏ธ Note that it will only show in results, when searching for the full alias!

#RustLang #Search #RustTip #Documentation #UX

Advanced features - The rustdoc book

#RustTip : When you are preparing for initial release of your crate, it is a good idea to run cargo-msrv (https://github.com/foresterre/cargo-msrv ) on it and record MSRV in your Cargo.toml
By doing so you will ensure, that later versions will not break someone's build because of implicit MSRV bump.

BTW, it is also a good idea to write about MSRV in Version Policy. (IMO, MSRV bump should be considered a breaking change).

GitHub - foresterre/cargo-msrv: ๐Ÿฆ€ Find the minimum supported Rust version (MSRV) for your project

๐Ÿฆ€ Find the minimum supported Rust version (MSRV) for your project - foresterre/cargo-msrv

GitHub

If you get weird #Rust #Lifetime #error's: have you already tried to just _remove_ the lifetime annotations and see what happens? You'll often get much better error messages this way.  

If this doesn't work and you still can't figure it out: try to not use references and own your values instead.

#RustLang #RustTip #RustTips #FerrisTipOfTheDay

Did you know that a lot of things in #Rust directly implement the `Ord` trait?

For example `Option<T>` where T: Ord

https://doc.rust-lang.org/std/option/enum.Option.html#impl-Ord-for-Option%3CT%3E

So you can do:

assert_eq(max(Some(0), Some(1)), Some(1))

assert_eq(max(Some(0), None), Some(0))

assert_eq(min(Some(0), None), None)

There are a lot of other things that implement `Ord`:
https://doc.rust-lang.org/std/cmp/trait.Ord.html#implementors

#RustLang #RustTips #RustTip

Option in std::option - Rust

The `Option` type. See the module level documentation for more.

Oh wow, did you know that in #Rust you can use Option as an iterator such that your types align, when you want to return a chain of iterators from a function, but also have an else case where the iterator is empty!?

I know, this was a mouthful.๐Ÿ˜ณ

Let's look at a playground that shows this:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=129eb419d767b71447b408e456773555

This trick is right from the docs on option:

https://doc.rust-lang.org/stable/std/option/#iterating-over-option

What a cunning trick!๐Ÿค“

Rust, I โค๏ธ you!

#RustTip #RustTips #RustLang

Rust Playground

A browser interface to the Rust compiler to experiment with the language

@follpvosten Nice! ๐Ÿ‘

Ok, I'll continue...๐Ÿ™‚

โœจ did you know โœจ

Since #Rust 1.56, std::collections::HashMap<K,V> impls From<[(K, V); N]>

This means the simplest way to create a HashMap is now:

HashMap::from([(1, "Love"), (2, "Rust")]);

https://doc.rust-lang.org/std/collections/hash_map/struct.HashMap.html#impl-From%3C%5B(K%2C%20V)%3B%20N%5D%3E-for-HashMap%3CK%2C%20V%2C%20RandomState%3E

#RustLang #RustTip

HashMap in std::collections::hash_map - Rust

A hash map implemented with quadratic probing and SIMD lookup.