diff options
| author | Hunter Kvalevog <hunter@kvog.sh> | 2026-10-02 21:53:51 -0500 |
|---|---|---|
| committer | Hunter Kvalevog <hunter@kvog.sh> | 2026-10-02 21:53:51 -0500 |
| commit | 6365466b189ef9e9f7257ecaefd5ef7643b58ba1 (patch) | |
| tree | 17ba62056d6b691dd0217b0e8f1b3a5826dce0f6 /rustlings/exercises/23_conversions/README.md | |
| parent | badfc4399714f594790d56f4d108f7e5f4605d03 (diff) | |
| download | demos-6365466b189ef9e9f7257ecaefd5ef7643b58ba1.tar.gz demos-6365466b189ef9e9f7257ecaefd5ef7643b58ba1.zip | |
Diffstat (limited to 'rustlings/exercises/23_conversions/README.md')
| -rw-r--r-- | rustlings/exercises/23_conversions/README.md | 23 |
1 files changed, 0 insertions, 23 deletions
diff --git a/rustlings/exercises/23_conversions/README.md b/rustlings/exercises/23_conversions/README.md deleted file mode 100644 index 619a78c..0000000 --- a/rustlings/exercises/23_conversions/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# Type conversions - -Rust offers a multitude of ways to convert a value of a given type into another type. - -The simplest form of type conversion is a type cast expression. It is denoted with the binary operator `as`. For instance, `println!("{}", 1 + 1.0);` would not compile, since `1` is an integer while `1.0` is a float. However, `println!("{}", 1 as f32 + 1.0)` should compile. The exercise [`using_as`](using_as.rs) tries to cover this. - -Rust also offers traits that facilitate type conversions upon implementation. These traits can be found under the [`convert`](https://doc.rust-lang.org/std/convert/index.html) module. -The traits are the following: - -- `From` and `Into` covered in [`from_into`](from_into.rs) -- `TryFrom` and `TryInto` covered in [`try_from_into`](try_from_into.rs) -- `AsRef` and `AsMut` covered in [`as_ref_mut`](as_ref_mut.rs) - -Furthermore, the `std::str` module offers a trait called [`FromStr`](https://doc.rust-lang.org/std/str/trait.FromStr.html) which helps with converting strings into target types via the `parse` method on strings. If properly implemented for a given type `Person`, then `let p: Person = "Mark,20".parse().unwrap()` should both compile and run without panicking. - -These should be the main ways ***within the standard library*** to convert data into your desired types. - -## Further information - -These are not directly covered in the book, but the standard library has a great documentation for it. - -- [conversions](https://doc.rust-lang.org/std/convert/index.html) -- [`FromStr` trait](https://doc.rust-lang.org/std/str/trait.FromStr.html) |
