mirror of
https://github.com/mainmatter/100-exercises-to-learn-rust
synced 2024-11-16 19:50:44 +01:00
misunderstand the implements verb (#18)
* Update 08_from.md * test * Update exercises/04_traits/08_from/src/lib.rs --------- Co-authored-by: datewu <hihahajun@gmail.com> Co-authored-by: Luca Palmieri <20745048+LukeMathWalker@users.noreply.github.com>
This commit is contained in:
parent
1d9ba4c25c
commit
44f3260fbe
2 changed files with 3 additions and 3 deletions
|
@ -105,7 +105,7 @@ though the former bound is implicit.
|
||||||
|
|
||||||
In [`std`'s documentation](https://doc.rust-lang.org/std/convert/trait.From.html#implementors)
|
In [`std`'s documentation](https://doc.rust-lang.org/std/convert/trait.From.html#implementors)
|
||||||
you can see which `std` types implement the `From` trait.
|
you can see which `std` types implement the `From` trait.
|
||||||
You'll find that `&str` implements `From<&str> for String`. Thus, we can write:
|
You'll find that `String` implements `From<&str> for String`. Thus, we can write:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
let title = String::from("A title");
|
let title = String::from("A title");
|
||||||
|
@ -129,7 +129,7 @@ where
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
If a type `T` implements `From<U>`, then `Into<U> for T` is automatically implemented. That's why
|
If a type `U` implements `From<T>`, then `Into<U> for T` is automatically implemented. That's why
|
||||||
we can write `let title = "A title".into();`.
|
we can write `let title = "A title".into();`.
|
||||||
|
|
||||||
## `.into()`
|
## `.into()`
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// TODO: Implement the `From` trait for the `u32` type to make `example` compile.
|
// TODO: Implement the `From` trait for the `WrappingU32` type to make `example` compile.
|
||||||
|
|
||||||
pub struct WrappingU32 {
|
pub struct WrappingU32 {
|
||||||
value: u32,
|
value: u32,
|
||||||
|
|
Loading…
Reference in a new issue