@@ -812,9 +812,48 @@ mod loop_keyword { }
812812//
813813/// Control flow based on pattern matching.
814814///
815- /// The documentation for this keyword is [not yet complete]. Pull requests welcome!
816- ///
817- /// [not yet complete]: https://github.com/rust-lang/rust/issues/34601
815+ /// `match` can be used to run code conditionally. Every pattern must
816+ /// be handled exhaustively either explicitly or by using wildcards like
817+ /// `_` in the `match`. Since `match` is an expression values can also be
818+ /// returned.
819+ ///
820+ /// ```rust
821+ /// let opt = Option::None::<usize>;
822+ /// let x = match opt {
823+ /// Some(int) => int,
824+ /// None => 10,
825+ /// }
826+ /// assert_eq!(x, 10);
827+ ///
828+ /// let a_number = Option::Some(10);
829+ /// match a_number {
830+ /// Some(x) if x <= 5 => println!("0 to 5 num = {}", x),
831+ /// Some(x @ 6..=10) => println!("6 to 10 num = {}", x),
832+ /// None => oh_no(),
833+ /// _ => all_other_numbers(),
834+ /// }
835+ /// ```
836+ ///
837+ /// `match` can be used to gain access to the inner members of an enum
838+ /// and use them directly.
839+ ///
840+ /// ```rust
841+ /// enum Outer {
842+ /// Double(Option<u8>, Option<String>),
843+ /// Single(Option<u8>),
844+ /// Empty
845+ /// }
846+ ///
847+ /// let get_inner = Outer::Double(None, Some(String::new()));
848+ /// match get_inner {
849+ /// Outer::Double(None, Some(st)) => println!("{}", st),
850+ /// Outer::Single(opt) => println!("{:?}", opt),
851+ /// _ => the_rest(),
852+ /// }
853+ /// ```
854+ ///
855+ /// For more information on `match` and matching in general, see the [Reference].
856+ /// [Reference]: ../reference/expressions/match-expr.html
818857mod match_keyword { }
819858
820859#[ doc( keyword = "mod" ) ]
@@ -831,9 +870,29 @@ mod mod_keyword { }
831870//
832871/// Capture a [closure]'s environment by value.
833872///
834- /// The documentation for this keyword is [not yet complete]. Pull requests welcome!
873+ /// `move` converts any variables captured by reference or mutable reference
874+ /// to owned by value variables. The three [`Fn` trait]'s mirror the ways to capture
875+ /// variables, when `move` is used the closures is represented by the `FnOnce` trait.
876+ ///
877+ /// ```rust
878+ ///
879+ /// ```
880+ ///
881+ /// `move` is often used when [threads] are involved.
882+ ///
883+ /// ```rust
884+ /// let x = 5;
885+ ///
886+ /// std::thread::spawn(move || {
887+ /// println!("captured {} by value", x)
888+ /// }).join().unwrap();
889+ ///
890+ /// // x is no longer available
891+ /// ```
835892///
836- /// [closure]: ../book/second-edition/ch13-01-closures.html
893+ /// [`Fn` trait]: ../std/ops/trait.Fn.html
894+ /// [closure]: ../book/ch13-01-closures.html
895+ /// [threads]: ../book/ch16-01-threads.html#using-move-closures-with-threads
837896/// [not yet complete]: https://github.com/rust-lang/rust/issues/34601
838897mod move_keyword { }
839898
0 commit comments