@@ -4,15 +4,15 @@ Functions are great, but if you want to call a bunch of them on some data, it
44can be awkward. Consider this code:
55
66``` {rust,ignore}
7- baz(bar(foo(x )));
7+ baz(bar(foo)));
88```
99
1010We would read this left-to right, and so we see "baz bar foo." But this isn't the
1111order that the functions would get called in, that's inside-out: "foo bar baz."
1212Wouldn't it be nice if we could do this instead?
1313
1414``` {rust,ignore}
15- x. foo() .bar().baz();
15+ foo.bar().baz();
1616```
1717
1818Luckily, as you may have guessed with the leading question, you can! Rust provides
@@ -47,11 +47,11 @@ This will print `12.566371`.
4747We've made a struct that represents a circle. We then write an ` impl ` block,
4848and inside it, define a method, ` area ` . Methods take a special first
4949parameter, of which there are three variants: ` self ` , ` &self ` , and ` &mut self ` .
50- You can think of this first parameter as being the ` x ` in ` x. foo()` . The three
51- variants correspond to the three kinds of thing ` x ` could be: ` self ` if it's
50+ You can think of this first parameter as being the ` foo ` in ` foo.bar () ` . The three
51+ variants correspond to the three kinds of things ` foo ` could be: ` self ` if it's
5252just a value on the stack, ` &self ` if it's a reference, and ` &mut self ` if it's
5353a mutable reference. We should default to using ` &self ` , as it's the most
54- common, as Rustaceans prefer borrowing over taking ownership, and references
54+ common, as Rustaceans prefer borrowing over taking ownership, and references
5555over mutable references. Here's an example of all three variants:
5656
5757``` rust
0 commit comments