Skip to content

Commit

Permalink
Fix documentation of as_(mut_)view
Browse files Browse the repository at this point in the history
  • Loading branch information
sosthene-nitrokey committed Jan 24, 2024
1 parent 48d2c87 commit 490c482
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -931,29 +931,40 @@ impl<T, const N: usize> Vec<T, N> {
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<T, N>` implements `Unsize<VecView<T>>`:
///
/// ```rust
/// use heapless::{Vec, VecView};
///# use heapless::{Vec, VecView};
/// let vec: Vec<u8, 10> = Vec::from_slice(&[1, 2, 3, 4]).unwrap();
/// let view: &VecView<u8> = vec.as_view();
/// ```
///
/// It is often preferable to do the same through type coerction, since `Vec<T, N>` implements `Unsize<VecView<T>>`:
///
/// ```rust
///# use heapless::{Vec, VecView};
/// let vec: Vec<u8, 10> = Vec::from_slice(&[1, 2, 3, 4]).unwrap();
/// let view: &VecView<_> = &vec;
/// let view: &VecView<u8> = &vec;
/// ```
pub const fn as_view(&self) -> &VecView<T> {
self
}

/// Get a `mut` reference to the Vec, erasing the `N` const-generic
///
/// This can also be used through type coerction, since `Vec<T, N>` implements `Unsize<VecView<T>>`:
/// 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<u8, 10> = Vec::from_slice(&[1, 2, 3, 4]).unwrap();
/// let view: &mut VecView<u8> = vec.as_mut_view();
/// ```
///
/// It is often preferable to do the same through type coerction, since `Vec<T, N>` implements `Unsize<VecView<T>>`:
///
/// ```rust
///# use heapless::{Vec, VecView};
/// let mut vec: Vec<u8, 10> = Vec::from_slice(&[1, 2, 3, 4]).unwrap();
/// let view: &mut VecView<_> = &mut vec;
/// let view: &mut VecView<u8> = &mut vec;
/// ```
pub fn as_mut_view(&mut self) -> &mut VecView<T> {
self
Expand Down

0 comments on commit 490c482

Please sign in to comment.