From 102ee5e70a3da9fa654c1515b492d0f2387e1f97 Mon Sep 17 00:00:00 2001 From: Mark-Simulacrum Date: Thu, 15 Sep 2016 19:47:04 -0600 Subject: [PATCH] Add example in AsMut trait documentation --- src/libcore/convert.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/libcore/convert.rs b/src/libcore/convert.rs index 5191cd7601064..5f16a4f2435f8 100644 --- a/src/libcore/convert.rs +++ b/src/libcore/convert.rs @@ -92,6 +92,22 @@ pub trait AsRef { /// [`Option`]: ../../std/option/enum.Option.html /// [`Result`]: ../../std/result/enum.Result.html /// +/// # Examples +/// +/// [`Box`] implements `AsMut`: +/// +/// [`Box`]: ../../std/boxed/struct.Box.html +/// +/// ``` +/// fn add_one>(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