File tree 2 files changed +34
-0
lines changed
2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 124
124
- [ Functions] ( scope/lifetime/fn.md )
125
125
- [ Methods] ( scope/lifetime/methods.md )
126
126
- [ Structs] ( scope/lifetime/struct.md )
127
+ - [ Traits] ( scope/lifetime/trait.md )
127
128
- [ Bounds] ( scope/lifetime/lifetime_bounds.md )
128
129
- [ Coercion] ( scope/lifetime/lifetime_coercion.md )
129
130
- [ Static] ( scope/lifetime/static_lifetime.md )
Original file line number Diff line number Diff line change
1
+ # Traits
2
+
3
+ Annotation of lifetimes in trait methods basically are similar to functions.
4
+ Note that ` impl ` may have annotation of lifetimes too.
5
+
6
+ ``` rust,editable
7
+ // A struct with annotation of lifetimes.
8
+ #[derive(Debug)]
9
+ struct Borrowed<'a> {
10
+ x: &'a i32,
11
+ }
12
+
13
+ // Annotate lifetimes to impl.
14
+ impl<'a> Default for Borrowed<'a> {
15
+ fn default() -> Self {
16
+ Self {
17
+ x: &10,
18
+ }
19
+ }
20
+ }
21
+
22
+ fn main() {
23
+ let b: Borrowed = Default::default();
24
+ println!("b is {:?}", b);
25
+ }
26
+ ```
27
+
28
+ ### See also:
29
+
30
+ [ ` trait ` s] [ trait ]
31
+
32
+
33
+ [ trait ] : trait.html
You can’t perform that action at this time.
0 commit comments