Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include the From trait in the generic traits slide #2570

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading