From b3734de08bb707916af47273cfab92ad819dcfcc Mon Sep 17 00:00:00 2001 From: "Dustin J. Mitchell" Date: Thu, 23 Jan 2025 03:43:43 -0500 Subject: [PATCH] Include the From trait in the generic traits slide (#2570) This saves a bunch of tabbing back and forth from the docs to the slide. --- src/generics/generic-traits.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/generics/generic-traits.md b/src/generics/generic-traits.md index 7df8af41..c7121dae 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