]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #23751 - tshepang:do-not-hardcode-the-growth, r=Manishearth
authorManish Goregaokar <manishsmail@gmail.com>
Sat, 28 Mar 2015 12:42:04 +0000 (18:12 +0530)
committerManish Goregaokar <manishsmail@gmail.com>
Sat, 28 Mar 2015 12:42:04 +0000 (18:12 +0530)
I found the arbitrary `10` surprising. A better method name, in such a case, would be `grow_by_10` :)

1  2 
src/doc/trpl/method-syntax.md

index 85472ff5db76727dde9dad6ec3a7f226305cb0b8,391b21c0f1c944468a2e40e9a36d3c829e984269..41ef705f0985bffde7126dde985fdd24f9541259
@@@ -46,7 -46,7 +46,7 @@@ This will print `12.566371`
  
  We've made a struct that represents a circle. We then write an `impl` block,
  and inside it, define a method, `area`. Methods take a  special first
 -parameter, `&self`. There are three variants: `self`, `&self`, and `&mut self`.
 +parameter, of which there are three variants: `self`, `&self`, and `&mut self`.
  You can think of this first parameter as being the `x` in `x.foo()`. The three
  variants correspond to the three kinds of thing `x` could be: `self` if it's
  just a value on the stack, `&self` if it's a reference, and `&mut self` if it's
@@@ -100,8 -100,8 +100,8 @@@ impl Circle 
          std::f64::consts::PI * (self.radius * self.radius)
      }
  
-     fn grow(&self) -> Circle {
-         Circle { x: self.x, y: self.y, radius: (self.radius * 10.0) }
+     fn grow(&self, increment: f64) -> Circle {
+         Circle { x: self.x, y: self.y, radius: self.radius + increment }
      }
  }
  
@@@ -109,7 -109,7 +109,7 @@@ fn main() 
      let c = Circle { x: 0.0, y: 0.0, radius: 2.0 };
      println!("{}", c.area());
  
-     let d = c.grow().area();
+     let d = c.grow(2.0).area();
      println!("{}", d);
  }
  ```
@@@ -124,7 -124,7 +124,7 @@@ fn grow(&self) -> Circle 
  ```
  
  We just say we're returning a `Circle`. With this method, we can grow a new
- circle with an area that's 100 times larger than the old one.
+ circle to any arbitrary size.
  
  ## Static methods