Skip to content

Commit 102ee5e

Browse files
Add example in AsMut trait documentation
1 parent 1265cbf commit 102ee5e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/libcore/convert.rs

+16
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,22 @@ pub trait AsRef<T: ?Sized> {
9292
/// [`Option<T>`]: ../../std/option/enum.Option.html
9393
/// [`Result<T, E>`]: ../../std/result/enum.Result.html
9494
///
95+
/// # Examples
96+
///
97+
/// [`Box<T>`] implements `AsMut<T>`:
98+
///
99+
/// [`Box<T>`]: ../../std/boxed/struct.Box.html
100+
///
101+
/// ```
102+
/// fn add_one<T: AsMut<u64>>(num: &mut T) {
103+
/// *num.as_mut() += 1;
104+
/// }
105+
///
106+
/// let mut boxed_num = Box::new(0);
107+
/// add_one(&mut boxed_num);
108+
/// assert_eq!(*boxed_num, 1);
109+
/// ```
110+
///
95111
/// # Generic Impls
96112
///
97113
/// - `AsMut` auto-dereferences if the inner type is a reference or a mutable

0 commit comments

Comments
 (0)