about
05/11/2022
RustBites - Conversions
Rust Bite - Conversions
most Rust conversions are explicit
1. Prologue
- Conversion from mutable to immutable, e.g., can pass a mutable reference to a function expecting an immutable reference.
-
Smart pointer dereferencing, e.g.,
Box<T> ,Rc<T> ,Arc<T> , andRefCell<T> implement theDeref trait. That means code can use theT interface through smart pointers without any explicit code boilerplate because the compiler automatically dereferences smart pointers where types wouldn't otherwise match.
2. Primitives
3. Strings
2. Other Types
3. References:
Link | Description |
---|---|
Cheats.rs | Very comprehensive collection of Rust facts in brief code snippets and comments. |
Cheats number-conversions | Conversions of primitive types. |
Cheats string-conversions | Conversions between String, &str, OsString, OsStr, PathBuf, and Path. |
Cheats string-output | Convert String contents for formatted output. |