sigmoid.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
A social space for people researching, working with, or just interested in AI!

Server stats:

575
active users

#rusttips

0 posts0 participants0 posts today

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

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

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

doc.rust-lang.org/std/option/e

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`:
doc.rust-lang.org/std/cmp/trai

doc.rust-lang.orgOption in std::option - RustThe `Option` type. See the module level documentation for more.