Skip to content

Commit 5704f20

Browse files
authored
Move From definition into code block (#2678)
1 parent c486dd9 commit 5704f20

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/generics/generic-traits.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ Minutes: 5
55
# Generic Traits
66

77
Traits can also be generic, just like types and functions. A trait's parameters
8-
get concrete types when it is used.
8+
get concrete types when it is used. For example the [`From<T>`][from] trait is
9+
used to define type conversions:
10+
11+
```rust
12+
pub trait From<T>: Sized {
13+
fn from(value: T) -> Self;
14+
}
15+
```
916

1017
```rust,editable
1118
#[derive(Debug)]
1219
struct Foo(String);
1320
14-
/* https://doc.rust-lang.org/stable/std/convert/trait.From.html
15-
*
16-
* pub trait From<T>: Sized {
17-
* fn from(value: T) -> Self;
18-
* }
19-
*/
20-
2121
impl From<u32> for Foo {
2222
fn from(from: u32) -> Foo {
2323
Foo(format!("Converted from integer: {from}"))
@@ -41,8 +41,7 @@ fn main() {
4141
<details>
4242

4343
- The `From` trait will be covered later in the course, but its
44-
[definition in the `std` docs](https://doc.rust-lang.org/std/convert/trait.From.html)
45-
is simple, and copied here for reference.
44+
[definition in the `std` docs][from] is simple, and copied here for reference.
4645

4746
- Implementations of the trait do not need to cover all possible type
4847
parameters. Here, `Foo::from("hello")` would not compile because there is no
@@ -58,3 +57,5 @@ fn main() {
5857
[specialization](https://rust-lang.github.io/rfcs/1210-impl-specialization.html).
5958

6059
</details>
60+
61+
[from]: https://doc.rust-lang.org/std/convert/trait.From.html

0 commit comments

Comments
 (0)