Skip to content

Commit 425aa23

Browse files
committed
Add examples in stdlib demonstrating the use syntax
1 parent 3bb20e3 commit 425aa23

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

library/core/src/marker.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,25 @@ impl<T: ?Sized> Copy for &T {}
465465
///
466466
/// The `UseCloned` trait does not provide a method; instead, it indicates that
467467
/// `Clone::clone` is lightweight, and allows the use of the `.use` syntax.
468+
///
469+
/// ## .use postfix syntax
470+
///
471+
/// Values can be `.use`d by adding `.use` postfix to the value you want to use.
472+
///
473+
/// ```
474+
/// fn foo(f: Foo) {
475+
/// // if `Foo` implements `Copy` f would be copied into x.
476+
/// // if `Foo` implements `UseCloned` f would be cloned into x.
477+
/// // otherwise f would be moved into x.
478+
/// let x = f.use;
479+
/// // ...
480+
/// }
481+
/// ```
482+
///
483+
/// ## use closures
484+
///
485+
/// Use closures allow captured values to be automatically used.
486+
/// This is similar to have a closure that you would call `.use` over each captured value.
468487
#[unstable(feature = "ergonomic_clones", issue = "132290")]
469488
#[cfg_attr(not(bootstrap), lang = "use_cloned")]
470489
#[marker]

library/std/src/keyword_docs.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2370,6 +2370,12 @@ mod where_keyword {}
23702370
/// [reference]: ../reference/expressions/loop-expr.html#predicate-loops
23712371
mod while_keyword {}
23722372

2373+
#[doc(keyword = "use")]
2374+
//
2375+
/// Use a values, copying its content if the value implements `Copy`, cloning the contents if the
2376+
/// value implements `UseCloned` or moving it otherwise.
2377+
mod use_keyword {}
2378+
23732379
// 2018 Edition keywords
23742380

23752381
#[doc(alias = "promise")]

0 commit comments

Comments
 (0)