@@ -1095,12 +1095,12 @@ typecheck:
1095
1095
# fn my_err(s: &str) -> ! { panic!() }
1096
1096
1097
1097
fn f(i: i32) -> i32 {
1098
- if i == 42 {
1099
- return 42;
1100
- }
1101
- else {
1102
- my_err("Bad number!");
1103
- }
1098
+ if i == 42 {
1099
+ return 42;
1100
+ }
1101
+ else {
1102
+ my_err("Bad number!");
1103
+ }
1104
1104
}
1105
1105
```
1106
1106
@@ -1399,9 +1399,9 @@ functions](#generic-functions).
1399
1399
1400
1400
```
1401
1401
trait Seq<T> {
1402
- fn len(&self) -> u32;
1403
- fn elt_at(&self, n: u32) -> T;
1404
- fn iter<F>(&self, F) where F: Fn(T);
1402
+ fn len(&self) -> u32;
1403
+ fn elt_at(&self, n: u32) -> T;
1404
+ fn iter<F>(&self, F) where F: Fn(T);
1405
1405
}
1406
1406
```
1407
1407
@@ -1579,8 +1579,12 @@ impl Shape for Circle {
1579
1579
fn draw(&self, s: Surface) { do_draw_circle(s, *self); }
1580
1580
fn bounding_box(&self) -> BoundingBox {
1581
1581
let r = self.radius;
1582
- BoundingBox{x: self.center.x - r, y: self.center.y - r,
1583
- width: 2.0 * r, height: 2.0 * r}
1582
+ BoundingBox {
1583
+ x: self.center.x - r,
1584
+ y: self.center.y - r,
1585
+ width: 2.0 * r,
1586
+ height: 2.0 * r,
1587
+ }
1584
1588
}
1585
1589
}
1586
1590
```
@@ -1615,10 +1619,10 @@ are written after the `impl` keyword.
1615
1619
```
1616
1620
# trait Seq<T> { fn dummy(&self, _: T) { } }
1617
1621
impl<T> Seq<T> for Vec<T> {
1618
- /* ... */
1622
+ /* ... */
1619
1623
}
1620
1624
impl Seq<bool> for u32 {
1621
- /* Treat the integer as a sequence of bits */
1625
+ /* Treat the integer as a sequence of bits */
1622
1626
}
1623
1627
```
1624
1628
@@ -1850,13 +1854,13 @@ An example of attributes:
1850
1854
// A function marked as a unit test
1851
1855
#[test]
1852
1856
fn test_foo() {
1853
- /* ... */
1857
+ /* ... */
1854
1858
}
1855
1859
1856
1860
// A conditionally-compiled module
1857
1861
#[cfg(target_os="linux")]
1858
1862
mod bar {
1859
- /* ... */
1863
+ /* ... */
1860
1864
}
1861
1865
1862
1866
// A lint attribute used to suppress a warning/error
@@ -2899,9 +2903,9 @@ An example of an `as` expression:
2899
2903
# fn len(values: &[f64]) -> i32 { 0 }
2900
2904
2901
2905
fn average(values: &[f64]) -> f64 {
2902
- let sum: f64 = sum(values);
2903
- let size: f64 = len(values) as f64;
2904
- sum / size
2906
+ let sum: f64 = sum(values);
2907
+ let size: f64 = len(values) as f64;
2908
+ sum / size
2905
2909
}
2906
2910
```
2907
2911
@@ -3207,9 +3211,9 @@ may be specified with `...`. For example:
3207
3211
# let x = 2;
3208
3212
3209
3213
let message = match x {
3210
- 0 | 1 => "not many",
3211
- 2 ... 9 => "a few",
3212
- _ => "lots"
3214
+ 0 | 1 => "not many",
3215
+ 2 ... 9 => "a few",
3216
+ _ => "lots"
3213
3217
};
3214
3218
```
3215
3219
@@ -3228,9 +3232,9 @@ may refer to the variables bound within the pattern they follow.
3228
3232
# fn process_other(i: i32) { }
3229
3233
3230
3234
let message = match maybe_digit {
3231
- Some(x) if x < 10 => process_digit(x),
3232
- Some(x) => process_other(x),
3233
- None => panic!()
3235
+ Some(x) if x < 10 => process_digit(x),
3236
+ Some(x) => process_other(x),
3237
+ None => panic!()
3234
3238
};
3235
3239
```
3236
3240
@@ -3274,10 +3278,10 @@ An example of a `return` expression:
3274
3278
3275
3279
```
3276
3280
fn max(a: i32, b: i32) -> i32 {
3277
- if a > b {
3278
- return a;
3279
- }
3280
- return b;
3281
+ if a > b {
3282
+ return a;
3283
+ }
3284
+ return b;
3281
3285
}
3282
3286
```
3283
3287
@@ -3521,7 +3525,7 @@ An example of a `fn` type:
3521
3525
3522
3526
```
3523
3527
fn add(x: i32, y: i32) -> i32 {
3524
- return x + y;
3528
+ return x + y;
3525
3529
}
3526
3530
3527
3531
let mut x = add(5,7);
@@ -3601,19 +3605,19 @@ An example of a trait object:
3601
3605
3602
3606
```
3603
3607
trait Printable {
3604
- fn stringify(&self) -> String;
3608
+ fn stringify(&self) -> String;
3605
3609
}
3606
3610
3607
3611
impl Printable for i32 {
3608
- fn stringify(&self) -> String { self.to_string() }
3612
+ fn stringify(&self) -> String { self.to_string() }
3609
3613
}
3610
3614
3611
3615
fn print(a: Box<Printable>) {
3612
- println!("{}", a.stringify());
3616
+ println!("{}", a.stringify());
3613
3617
}
3614
3618
3615
3619
fn main() {
3616
- print(Box::new(10) as Box<Printable>);
3620
+ print(Box::new(10) as Box<Printable>);
3617
3621
}
3618
3622
```
3619
3623
@@ -3628,7 +3632,7 @@ its type parameters are types:
3628
3632
``` ignore
3629
3633
fn to_vec<A: Clone>(xs: &[A]) -> Vec<A> {
3630
3634
if xs.is_empty() {
3631
- return vec![];
3635
+ return vec![];
3632
3636
}
3633
3637
let first: A = xs[0].clone();
3634
3638
let mut rest: Vec<A> = to_vec(&xs[1..]);
@@ -3648,7 +3652,7 @@ it is an alias for the implementing type. For example, in:
3648
3652
3649
3653
```
3650
3654
trait Printable {
3651
- fn make_string(&self) -> String;
3655
+ fn make_string(&self) -> String;
3652
3656
}
3653
3657
3654
3658
impl Printable for String {
@@ -3716,7 +3720,7 @@ sites are:
3716
3720
fn bar (_ : i8 ) { }
3717
3721
3718
3722
fn main () {
3719
- bar (128 );
3723
+ bar (128 );
3720
3724
}
3721
3725
```
3722
3726
0 commit comments