File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -69,7 +69,20 @@ pub struct Foo<T: Sized>
69
69
}
70
70
```
71
71
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** :
73
86
74
87
``` rust
75
88
pub struct Foo <T : ? Sized > {
@@ -82,8 +95,6 @@ pub struct Foo<T: ?Sized> {
82
95
This syntax reads as "` T ` may or may not be ` Sized ` ", and it allows you to
83
96
bind ` T ` to a DST (e.g. ` Foo<str> ` ). It is a special case, though: negative trait bounds are exclusive to ` Sized ` ,
84
97
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.
87
98
88
99
## ` &str ` to ` String `
89
100
You can’t perform that action at this time.
0 commit comments