Skip to main content

52 posts tagged with "Rust"

Rust Programming Language and Its Toolchain

View All Tags

How to Convert a &str to a String in Rust

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

Rust has two main string types. &str is a borrowed view of text, such as a string literal, and String is text your code owns. When a variable, a struct field or a function needs a String, convert the &str with to_owned(), to_string() or String::from().

How to Use #[derive] in Rust

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

#[derive] asks the compiler to write standard trait implementations for your struct. With Debug, Clone and PartialEq derived, a struct can be printed with {:?}, copied with .clone() and compared with ==, without writing those methods by hand.

How to Import Items in Rust with use

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

Rust code refers to items from other modules and crates by their path, such as std::collections::HashMap. A use declaration brings that path into scope once, so the rest of the file can simply say HashMap.