remove out of date text from tutorial regarding iface-less impls

This commit is contained in:
Niko Matsakis 2012-07-18 15:34:12 -07:00
parent 3ac5b4a86f
commit 9c1dea5eb2

View File

@ -485,7 +485,7 @@ and function signatures in the surrounding program. For example, here
the type of `x` is inferred to be `u16` because it is passed to a the type of `x` is inferred to be `u16` because it is passed to a
function that takes a `u16` argument: function that takes a `u16` argument:
~~~~~ ~~~~
let x = 3; let x = 3;
fn identity_u16(n: u16) -> u16 { n } fn identity_u16(n: u16) -> u16 { n }
@ -497,7 +497,7 @@ On the other hand, if the program gives conflicting information about
what the type of the unsuffixed literal should be, you'll get an error what the type of the unsuffixed literal should be, you'll get an error
message. message.
~~~~~{.xfail-test} ~~~~{.xfail-test}
let x = 3; let x = 3;
let y: i32 = 3; let y: i32 = 3;
@ -2572,27 +2572,11 @@ more expensive than statically resolved method calls.
If you only intend to use an implementation for static overloading, If you only intend to use an implementation for static overloading,
and there is no interface available that it conforms to, you are free and there is no interface available that it conforms to, you are free
to leave off the `of` clause. to leave off the `of` clause. However, this is only possible when you
are defining an implementation in the same module as the receiver
~~~~ type, and the receiver type is a named type (i.e., an enum or a
# type currency = (); class); [single-variant enums](#single_variant_enum) are a common
# fn mk_currency(x: int, s: ~str) {} choice.
impl int_util for int {
fn times(b: fn(int)) {
let mut i = 0;
while i < self { b(i); i += 1; }
}
fn dollars() -> currency {
mk_currency(self, ~"USD")
}
}
~~~~
This allows cutesy things like `send_payment(10.dollars())`. And the
nice thing is that it's fully scoped, so the uneasy feeling that
anybody with experience in object-oriented languages (with the
possible exception of Rubyists) gets at the sight of such things is
not justified. It's harmless!
# Interacting with foreign code # Interacting with foreign code