Skip to content

Commit

Permalink
Include the From trait in the generic traits slide (#2570)
Browse files Browse the repository at this point in the history
This saves a bunch of tabbing back and forth from the docs to the slide.
  • Loading branch information
djmitche authored Jan 23, 2025
1 parent b3c57e4 commit b3734de
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/generics/generic-traits.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>: Sized {
* fn from(value: T) -> Self;
* }
*/
impl From<u32> for Foo {
fn from(from: u32) -> Foo {
Foo(format!("Converted from integer: {from}"))
Expand All @@ -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
Expand Down

0 comments on commit b3734de

Please sign in to comment.