about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMark-Simulacrum <mark.simulacrum@gmail.com>2016-09-15 19:47:04 -0600
committerMark-Simulacrum <mark.simulacrum@gmail.com>2016-09-15 19:47:04 -0600
commit102ee5e70a3da9fa654c1515b492d0f2387e1f97 (patch)
tree6d1b52ef41a97d1bda3cf495f21e4a2868d47b74 /src
parent1265cbf4e05628c98f51afebe0b662c451173faa (diff)
downloadrust-102ee5e70a3da9fa654c1515b492d0f2387e1f97.tar.gz
rust-102ee5e70a3da9fa654c1515b492d0f2387e1f97.zip
Add example in AsMut trait documentation
Diffstat (limited to 'src')
-rw-r--r--src/libcore/convert.rs16
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