diff --git a/src/generics/generic-traits.md b/src/generics/generic-traits.md index 7df8af412450..c7121dae3372 100644 --- a/src/generics/generic-traits.md +++ b/src/generics/generic-traits.md @@ -11,6 +11,13 @@ get concrete types when it is used. #[derive(Debug)] struct Foo(String); +/* https://doc.rust-lang.org/stable/std/convert/trait.From.html + * + * pub trait From: Sized { + * fn from(value: T) -> Self; + * } + */ + impl From for Foo { fn from(from: u32) -> Foo { Foo(format!("Converted from integer: {from}")) @@ -34,7 +41,7 @@ fn main() { - The `From` trait will be covered later in the course, but its [definition in the `std` docs](https://doc.rust-lang.org/std/convert/trait.From.html) - is simple. + is simple, and copied here for reference. - Implementations of the trait do not need to cover all possible type parameters. Here, `Foo::from("hello")` would not compile because there is no