Skip to content

Commit 3050281

Browse files
committed
---
yaml --- r: 22606 b: refs/heads/master c: 9c1dea5 h: refs/heads/master v: v3
1 parent c6ea222 commit 3050281

File tree

2 files changed

+8
-24
lines changed

2 files changed

+8
-24
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 3ac5b4a86fa37d2b2c17ef5ffdb6e521630ea4ac
2+
refs/heads/master: 9c1dea5eb247c505ff050b6cf0aa13d260b872e5
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/doc/tutorial.md

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ and function signatures in the surrounding program. For example, here
485485
the type of `x` is inferred to be `u16` because it is passed to a
486486
function that takes a `u16` argument:
487487

488-
~~~~~
488+
~~~~
489489
let x = 3;
490490
491491
fn identity_u16(n: u16) -> u16 { n }
@@ -497,7 +497,7 @@ On the other hand, if the program gives conflicting information about
497497
what the type of the unsuffixed literal should be, you'll get an error
498498
message.
499499

500-
~~~~~{.xfail-test}
500+
~~~~{.xfail-test}
501501
let x = 3;
502502
let y: i32 = 3;
503503
@@ -2572,27 +2572,11 @@ more expensive than statically resolved method calls.
25722572

25732573
If you only intend to use an implementation for static overloading,
25742574
and there is no interface available that it conforms to, you are free
2575-
to leave off the `of` clause.
2576-
2577-
~~~~
2578-
# type currency = ();
2579-
# fn mk_currency(x: int, s: ~str) {}
2580-
impl int_util for int {
2581-
fn times(b: fn(int)) {
2582-
let mut i = 0;
2583-
while i < self { b(i); i += 1; }
2584-
}
2585-
fn dollars() -> currency {
2586-
mk_currency(self, ~"USD")
2587-
}
2588-
}
2589-
~~~~
2590-
2591-
This allows cutesy things like `send_payment(10.dollars())`. And the
2592-
nice thing is that it's fully scoped, so the uneasy feeling that
2593-
anybody with experience in object-oriented languages (with the
2594-
possible exception of Rubyists) gets at the sight of such things is
2595-
not justified. It's harmless!
2575+
to leave off the `of` clause. However, this is only possible when you
2576+
are defining an implementation in the same module as the receiver
2577+
type, and the receiver type is a named type (i.e., an enum or a
2578+
class); [single-variant enums](#single_variant_enum) are a common
2579+
choice.
25962580

25972581
# Interacting with foreign code
25982582

0 commit comments

Comments
 (0)