diff options
| author | Jonathan Turner <jonathandturner@users.noreply.github.com> | 2016-09-16 09:29:49 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-09-16 09:29:49 -0700 |
| commit | 919cbc01684d7310d053f5cba38baacc84c07492 (patch) | |
| tree | 2973df29511dcbbfe240121f91379450b1e027fe /src | |
| parent | c6f1db6f6072fefec1249fe2339d6f44ae8e4371 (diff) | |
| parent | 102ee5e70a3da9fa654c1515b492d0f2387e1f97 (diff) | |
| download | rust-919cbc01684d7310d053f5cba38baacc84c07492.tar.gz rust-919cbc01684d7310d053f5cba38baacc84c07492.zip | |
Rollup merge of #36519 - Mark-Simulacrum:example-asmut, r=GuillaumeGomez
Add example in AsMut trait documentation Let me know of any changes I should make. r? @GuillaumeGomez
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcore/convert.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/libcore/convert.rs b/src/libcore/convert.rs index 5191cd76010..5f16a4f2435 100644 --- a/src/libcore/convert.rs +++ b/src/libcore/convert.rs @@ -92,6 +92,22 @@ pub trait AsRef<T: ?Sized> { /// [`Option<T>`]: ../../std/option/enum.Option.html /// [`Result<T, E>`]: ../../std/result/enum.Result.html /// +/// # Examples +/// +/// [`Box<T>`] implements `AsMut<T>`: +/// +/// [`Box<T>`]: ../../std/boxed/struct.Box.html +/// +/// ``` +/// fn add_one<T: AsMut<u64>>(num: &mut T) { +/// *num.as_mut() += 1; +/// } +/// +/// let mut boxed_num = Box::new(0); +/// add_one(&mut boxed_num); +/// assert_eq!(*boxed_num, 1); +/// ``` +/// /// # Generic Impls /// /// - `AsMut` auto-dereferences if the inner type is a reference or a mutable |
