UTF-32 string.
A value of type `str` is a Unicode string, represented as an array of 8-bit
-unsigned bytes holding a sequence of UTF-8 codepoints. Since `str` is of
+unsigned bytes holding a sequence of UTF-8 code points. Since `str` is of
unknown size, it is not a _first-class_ type, but can only be instantiated
- through a pointer type, such as `&str` or `String`.
+ through a pointer type, such as `&str`.
### Tuple types
### Closure types
- ```{.ebnf .notation}
- closure_type := [ 'unsafe' ] [ '<' lifetime-list '>' ] '|' arg-list '|'
- [ ':' bound-list ] [ '->' type ]
- lifetime-list := lifetime | lifetime ',' lifetime-list
- arg-list := ident ':' type | ident ':' type ',' arg-list
- bound-list := bound | bound '+' bound-list
- bound := path | lifetime
- ```
-
- The type of a closure mapping an input of type `A` to an output of type `B` is
- `|A| -> B`. A closure with no arguments or return values has type `||`.
-
- An example of creating and calling a closure:
+ A [lambda expression](#lambda-expressions) produces a closure value with
+ a unique, anonymous type that cannot be written out.
- ```rust
- let captured_var = 10;
+ Depending on the requirements of the closure, its type implements one or
+ more of the closure traits:
- let closure_no_args = || println!("captured_var={}", captured_var);
+ * `FnOnce`
+ : The closure can be called once. A closure called as `FnOnce`
+ can move out values from its environment.
- let closure_args = |arg: i32| -> i32 {
- println!("captured_var={}, arg={}", captured_var, arg);
- arg // Note lack of semicolon after 'arg'
- };
+ * `FnMut`
+ : The closure can be called multiple times as mutable. A closure called as
+ `FnMut` can mutate values from its environment. `FnMut` implies
+ `FnOnce`.
- fn call_closure<F: Fn(), G: Fn(i32) -> i32>(c1: F, c2: G) {
- c1();
- c2(2);
- }
+ * `Fn`
+ : The closure can be called multiple times through a shared reference.
+ A closure called as `Fn` can neither move out from nor mutate values
+ from its environment. `Fn` implies `FnMut` and `FnOnce`.
- call_closure(closure_no_args, closure_args);
-
- ```
-### Object types
+### Trait objects
Every trait item (see [traits](#traits)) defines a type with the same name as
-the trait. This type is called the _object type_ of the trait. Object types
+the trait. This type is called the _trait object_ of the trait. Trait objects
permit "late binding" of methods, dispatched using _virtual method tables_
("vtables"). Whereas most calls to trait methods are "early bound" (statically
resolved) to specific implementations at compile time, a call to a method on an