From 05096fd4e85e3671217835df8930f835682ad769 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Wed, 24 Jan 2024 09:48:40 +0100 Subject: [PATCH] Fix documentation of as_(mut_)view --- src/vec.rs | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) 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