## Attributes
~~~~ {.notrust .ebnf .gram}
- attribute : '#' '!' ? '[' attr_list ']' ;
- attr_list : attr [ ',' attr_list ]* ;
- attr : ident [ '=' literal
- | '(' attr_list ')' ] ? ;
+ attribute : '#' '!' ? '[' meta_item ']' ;
+ meta_item : ident [ '=' literal
+ | '(' meta_seq ')' ] ? ;
+ meta_seq : meta_item [ ',' meta_seq ]* ;
~~~~
Static entities in Rust — crates, modules and items — may have _attributes_
Within the body of an item that has type parameter declarations, the names of its type parameters are types:
~~~~
-fn map<A: Clone, B: Clone>(f: |A| -> B, xs: &[A]) -> ~[B] {
+fn map<A: Clone, B: Clone>(f: |A| -> B, xs: &[A]) -> Vec<B> {
if xs.len() == 0 {
- return ~[];
+ return vec![];
}
let first: B = f(xs[0].clone());
- let rest: ~[B] = map(f, xs.slice(1, xs.len()));
- return ~[first] + rest;
+ let rest: Vec<B> = map(f, xs.slice(1, xs.len()));
+ return vec![first].append(rest.as_slice());
}
~~~~
Here, `first` has type `B`, referring to `map`'s `B` type parameter;
-and `rest` has type `~[B]`, a vector type with element type `B`.
+and `rest` has type `Vec<B>`, a vector type with element type `B`.
### Self types