diff --git a/src/vec.rs b/src/vec.rs index 7d3f0fd916..be7aaf30a9 100644 --- a/src/vec.rs +++ b/src/vec.rs @@ -931,29 +931,40 @@ impl Vec { new } - /// Get a reference to the Vec, erasing the `N` const-generic + /// Get a reference to the `Vec`, erasing the `N` const-generic. /// - /// This can also be used through type coerction, since `Vec` implements `Unsize>`: /// /// ```rust - /// use heapless::{Vec, VecView}; + /// # use heapless::{Vec, VecView}; + /// let vec: Vec = Vec::from_slice(&[1, 2, 3, 4]).unwrap(); + /// let view: &VecView = vec.as_view(); + /// ``` /// + /// It is often preferable to do the same through type coerction, since `Vec` implements `Unsize>`: + /// + /// ```rust + /// # use heapless::{Vec, VecView}; /// let vec: Vec = Vec::from_slice(&[1, 2, 3, 4]).unwrap(); - /// let view: &VecView<_> = &vec; + /// let view: &VecView = &vec; /// ``` pub const fn as_view(&self) -> &VecView { self } - /// Get a `mut` reference to the Vec, erasing the `N` const-generic - /// - /// This can also be used through type coerction, since `Vec` implements `Unsize>`: + /// Get a mutable reference to the `Vec`, erasing the `N` const-generic. /// /// ```rust - /// use heapless::{Vec, VecView}; + /// # use heapless::{Vec, VecView}; + /// let mut vec: Vec = Vec::from_slice(&[1, 2, 3, 4]).unwrap(); + /// let view: &mut VecView = vec.as_mut_view(); + /// ``` /// + /// It is often preferable to do the same through type coerction, since `Vec` implements `Unsize>`: + /// + /// ```rust + /// # use heapless::{Vec, VecView}; /// let mut vec: Vec = Vec::from_slice(&[1, 2, 3, 4]).unwrap(); - /// let view: &mut VecView<_> = &mut vec; + /// let view: &mut VecView = &mut vec; /// ``` pub fn as_mut_view(&mut self) -> &mut VecView { self