@@ -485,7 +485,7 @@ and function signatures in the surrounding program. For example, here
485
485
the type of ` x ` is inferred to be ` u16 ` because it is passed to a
486
486
function that takes a ` u16 ` argument:
487
487
488
- ~~~~~
488
+ ~~~~
489
489
let x = 3;
490
490
491
491
fn identity_u16(n: u16) -> u16 { n }
@@ -497,7 +497,7 @@ On the other hand, if the program gives conflicting information about
497
497
what the type of the unsuffixed literal should be, you'll get an error
498
498
message.
499
499
500
- ~~~~~ {.xfail-test}
500
+ ~~~~ {.xfail-test}
501
501
let x = 3;
502
502
let y: i32 = 3;
503
503
@@ -2572,27 +2572,11 @@ more expensive than statically resolved method calls.
2572
2572
2573
2573
If you only intend to use an implementation for static overloading,
2574
2574
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.
2596
2580
2597
2581
# Interacting with foreign code
2598
2582
0 commit comments