File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 124124 - [ Functions] ( scope/lifetime/fn.md )
125125 - [ Methods] ( scope/lifetime/methods.md )
126126 - [ Structs] ( scope/lifetime/struct.md )
127+ - [ Traits] ( scope/lifetime/trait.md )
127128 - [ Bounds] ( scope/lifetime/lifetime_bounds.md )
128129 - [ Coercion] ( scope/lifetime/lifetime_coercion.md )
129130 - [ 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