]> git.lizzy.rs Git - rust.git/commitdiff
Document the question mark operator
authorest31 <MTest31@outlook.com>
Wed, 9 Nov 2016 06:23:57 +0000 (07:23 +0100)
committerest31 <MTest31@outlook.com>
Wed, 9 Nov 2016 07:37:05 +0000 (08:37 +0100)
src/doc/book/syntax-index.md
src/doc/reference.md

index 1e05b01d30d46531843a8b1a3cd45767f0013772..28403711cd701f212db25d4e9b59cbdf69b47a3b 100644 (file)
@@ -94,6 +94,7 @@
 * `|=` (`var |= expr`): bitwise or & assignment. Overloadable (`BitOrAssign`).
 * `||` (`expr || expr`): logical or.
 * `_`: "ignored" pattern binding (see [Patterns (Ignoring bindings)]). Also used to make integer-literals readable (see [Reference (Integer literals)]).
+* `?` (`expr?`): Error propagation. Returns early when `Err(_)` is encountered, unwraps otherwise. Similar to the [`try!` macro].
 
 ## Other Syntax
 
 [Functions]: functions.html
 [Generics]: generics.html
 [Iterators]: iterators.html
+[`try!` macro]: error-handling.html#the-try-macro
 [Lifetimes]: lifetimes.html
 [Loops (`for`)]: loops.html#for
 [Loops (`loop`)]: loops.html#loop
index 4838ecd2d42e62108b156dd760d9c8eb19b9942e..eb3a6c0de6d42319493000bac2ff9043b1c7e930 100644 (file)
@@ -2860,8 +2860,8 @@ assert_eq!(x, y);
 
 ### Unary operator expressions
 
-Rust defines the following unary operators. They are all written as prefix operators,
-before the expression they apply to.
+Rust defines the following unary operators. With the exception of `?`, they are
+all written as prefix operators, before the expression they apply to.
 
 * `-`
   : Negation. Signed integer types and floating-point types support negation. It
@@ -2890,6 +2890,10 @@ before the expression they apply to.
     If the `&` or `&mut` operators are applied to an rvalue, a
     temporary value is created; the lifetime of this temporary value
     is defined by [syntactic rules](#temporary-lifetimes).
+* `?`
+  : Propagating errors if applied to `Err(_)` and unwrapping if
+    applied to `Ok(_)`. Only works on the `Result<T, E>` type,
+    and written in postfix notation.
 
 ### Binary operator expressions