[rust-dev] Interfaces!

Niko Matsakis niko at alum.mit.edu
Thu Jan 5 11:18:35 PST 2012


Sorry, the *syntax* is not inconsistent.  The *docs* are inconsistent, I 
believe.  The first example says:

|// This implements an interface `iter_util` for vector types
impl iter_util<T>  for [T] {
     fn len() ->  uint { std::vec::len(self) }
     fn iter(f: block(T)) { for elt in self { f(elt); } }
     fn map<U>(f: block(T) ->  U) ->  [U] {
         let rslt = [];
         for elt in self { rslt += [f(elt)]; }
         rslt
     }
}|

but this leading comment is incorrect.


Niko

On 1/5/12 11:16 AM, Marijn Haverbeke wrote:
>> If I write "impl foo for bar" does that define an impl
>> named `foo` with no interface, or an impl of the interface `foo`?
> No interface.
>
>>   In that case, I write "impl of foo for bar" to get an impl of
>> the interface `foo` named `foo` for the type `bar`?
> Correct. How is this inconsistent? There's an optional `of` clause to
> specify the interface. As an abbreviation, you can leave off the
> proper name when you want to use the name of the interface (and you
> specified one).



More information about the Rust-dev mailing list