mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-05-15 09:48:45 +00:00
docs: update README after rebase
This commit is contained in:
parent
5b1edf5f4f
commit
ef99b5cb9e
@ -2,14 +2,14 @@
|
|||||||
|
|
||||||
Rust offers a multitude of ways to convert a value of a given type into another type.
|
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.
|
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 [`conversions1`](conversions1.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.
|
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:
|
The traits are the following:
|
||||||
|
|
||||||
- `From` and `Into` covered in [`from_into`](from_into.rs)
|
- `From` and `Into` covered in [`conversions2`](conversions2.rs)
|
||||||
- `TryFrom` and `TryInto` covered in [`try_from_into`](try_from_into.rs)
|
- `TryFrom` and `TryInto` covered in [`conversions4`](conversions4.rs)
|
||||||
- `AsRef` and `AsMut` covered in [`as_ref_mut`](as_ref_mut.rs)
|
- `AsRef` and `AsMut` covered in [`conversions5`](conversions5.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.
|
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.
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user