Skip to content

Commit 3056930

Browse files
authored
Merge pull request #1236 from rusty-snake/patch-2
generics/impl.md: follow rustfmt style
2 parents 9dfb263 + be04051 commit 3056930

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/generics/impl.md

+13-9
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,43 @@ Similar to functions, implementations require care to remain generic.
44

55
```rust
66
struct S; // Concrete type `S`
7-
struct GenericVal<T>(T,); // Generic type `GenericVal`
7+
struct GenericVal<T>(T); // Generic type `GenericVal`
88

99
// impl of GenericVal where we explicitly specify type parameters:
1010
impl GenericVal<f32> {} // Specify `f32`
1111
impl GenericVal<S> {} // Specify `S` as defined above
1212

1313
// `<T>` Must precede the type to remain generic
14-
impl <T> GenericVal<T> {}
14+
impl<T> GenericVal<T> {}
1515
```
1616

1717
```rust,editable
1818
struct Val {
19-
val: f64
19+
val: f64,
2020
}
2121
22-
struct GenVal<T>{
23-
gen_val: T
22+
struct GenVal<T> {
23+
gen_val: T,
2424
}
2525
2626
// impl of Val
2727
impl Val {
28-
fn value(&self) -> &f64 { &self.val }
28+
fn value(&self) -> &f64 {
29+
&self.val
30+
}
2931
}
3032
3133
// impl of GenVal for a generic type `T`
32-
impl <T> GenVal<T> {
33-
fn value(&self) -> &T { &self.gen_val }
34+
impl<T> GenVal<T> {
35+
fn value(&self) -> &T {
36+
&self.gen_val
37+
}
3438
}
3539
3640
fn main() {
3741
let x = Val { val: 3.0 };
3842
let y = GenVal { gen_val: 3i32 };
39-
43+
4044
println!("{}, {}", x.value(), y.value());
4145
}
4246
```

0 commit comments

Comments
 (0)