Skip to content

Commit cbafcf2

Browse files
Restructure negative trait bounds section.
1 parent d5c0743 commit cbafcf2

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

book/src/04_traits/09_from.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,20 @@ pub struct Foo<T: Sized>
6969
}
7070
```
7171

72-
You can opt out of this behavior by using a **negative trait bound**:
72+
In the case of `From<T>`, the trait definition is equivalent to:
73+
74+
```rust
75+
pub trait From<T: Sized>: Sized {
76+
fn from(value: T) -> Self;
77+
}
78+
```
79+
80+
In other words, _both_ `T` and the type implementing `From<T>` must be `Sized`, even
81+
though the former bound is implicit.
82+
83+
### Negative trait bounds
84+
85+
You can opt out of the implicit `Sized` bound with a **negative trait bound**:
7386

7487
```rust
7588
pub struct Foo<T: ?Sized> {
@@ -82,8 +95,6 @@ pub struct Foo<T: ?Sized> {
8295
This syntax reads as "`T` may or may not be `Sized`", and it allows you to
8396
bind `T` to a DST (e.g. `Foo<str>`). It is a special case, though: negative trait bounds are exclusive to `Sized`,
8497
you can't use them with other traits.
85-
In the case of `From<T>`, we want _both_ `T` and the type implementing `From<T>` to be `Sized`, even
86-
though the former bound is implicit.
8798

8899
## `&str` to `String`
89100

0 commit comments

Comments
 (0)