Commit b113f58 1 parent 91e8044 commit b113f58 Copy full SHA for b113f58
File tree 1 file changed +35
-0
lines changed
1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -3603,6 +3603,41 @@ fn main() {
3603
3603
In this example, the trait ` Printable ` occurs as a trait object in both the
3604
3604
type signature of ` print ` , and the cast expression in ` main ` .
3605
3605
3606
+ Trait objects may contain references, and so those references will need a
3607
+ lifetime. If the trait contains some sort of lifetime bound, like this:
3608
+
3609
+ ``` rust,ignore
3610
+ // Some trait like this...
3611
+ trait Bar<'a>: 'a { }
3612
+
3613
+ // ... means these are the same:
3614
+ Box<Bar>
3615
+ Box<Bar + 'a>
3616
+ ```
3617
+
3618
+ If there’s no bound, then the default lifetime is the same as the pointer that
3619
+ the trait object is behind:
3620
+
3621
+ ``` rust,ignore
3622
+ // Some trait like this...
3623
+ trait Bar { }
3624
+
3625
+ // ... means these are the same:
3626
+ &Bar
3627
+ &'a (Bar + 'a)
3628
+ ```
3629
+
3630
+ In any other case, the default is ` 'static ` :
3631
+
3632
+ ``` rust,ignore
3633
+ // Some trait like this...
3634
+ trait Bar { }
3635
+
3636
+ // ... means these are the same:
3637
+ Box<Bar>
3638
+ Box<Bar + 'static>
3639
+ ```
3640
+
3606
3641
### Type parameters
3607
3642
3608
3643
Within the body of an item that has type parameter declarations, the names of
You can’t perform that action at this time.
0 commit comments