mastouille.fr est l'un des nombreux serveurs Mastodon indépendants que vous pouvez utiliser pour participer au fédiverse.
Mastouille est une instance Mastodon durable, ouverte, et hébergée en France.

Administré par :

Statistiques du serveur :

577
comptes actifs

#rusttips

0 message0 participant0 message aujourd’hui

Some #Rust string literal #trivia - the following are equal:

let s = "one line string";

let s = "one line \
string";

And these ones are also equal:

let lines = "a\nmultiline\nstring";

let lines = "a
multiline
string";

and now my favorite... 🥁

let lines = "a\n\
multiline\n\
string";

Playground:
play.rust-lang.org/?version=st

play.rust-lang.orgRust PlaygroundA browser interface to the Rust compiler to experiment with the language

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:
play.rust-lang.org/?version=st

This trick is right from the docs on option:

doc.rust-lang.org/stable/std/o

What a cunning trick!🤓

Rust, I ❤️ you!

play.rust-lang.orgRust PlaygroundA browser interface to the Rust compiler to experiment with the language

✨ Rust Challenge explained

Ans:
2. A gives output and B gives error

In `A` code:
👉 x will be assigned to i8 type since we are using i8 to compare in assert_eq.

👉 x.pow(6) will be 2 power 6 which is 64, it will work perfectly

In `B` code:

👉 x will be assigned default to i32

👉 But in second line you will get ambiguity error 🤯

👉 And compiler will ask to specify the type for x explicitly