1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-03-20 06:21:09 +02:00

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.
This commit is contained in:
Dustin J. Mitchell 2025-01-23 03:43:43 -05:00 committed by GitHub
parent b3c57e4cbf
commit b3734de08b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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}"))
@ -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