Skip to main content

24 posts tagged with "Rust"

Rust Programming Language and Its Toolchain

View All Tags

How to Read an Environment Variable in Rust

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

Settings that change between computers, such as a database address or an API key, belong in environment variables. Rust reads them with std::env::var, which returns the value as a Result, and unwrap_or_default() turns a missing variable into an empty string.

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.