mirror of
https://github.com/rosenpass/rosenpass.git
synced 2026-02-28 06:23:08 -08:00
docs(util): fix doc reference in the zerocopy module
This commit is contained in:
@@ -3,16 +3,17 @@
|
||||
//!
|
||||
//! It offers the following primary abstractions and traits:
|
||||
//!
|
||||
//! - [`RefMaker`]: A helper structure for safely creating
|
||||
//! [`Ref`](zerocopy::Ref) references from byte slices.
|
||||
//! - [`ZerocopyEmancipateExt`]: A trait to convert `Ref<B, T>` into a borrowed
|
||||
//! `Ref<&[u8], T>`.
|
||||
//! - [`ZerocopyEmancipateMutExt`]: A trait to convert `Ref<B, T>` into a
|
||||
//! borrowed mutable `Ref<&mut [u8], T>`.
|
||||
//! - [`ZerocopySliceExt`]: Extension methods for parsing byte slices into
|
||||
//! zero-copy references.
|
||||
//! - [`ZerocopyMutSliceExt`]: Extension methods for parsing and zeroizing byte
|
||||
//! slices into zero-copy references.
|
||||
//! - [`RefMaker`](crate::zerocopy::RefMaker): A helper structure for safely
|
||||
//! creating `zerocopy::Ref` references from byte slices.
|
||||
//! - [`ZerocopyEmancipateExt`](crate::zerocopy::ZerocopyEmancipateExt):
|
||||
//! A trait to convert `Ref<B, T>` into a borrowed `Ref<&[u8], T>`.
|
||||
//! - [`ZerocopyEmancipateMutExt`](crate::zerocopy::ZerocopyEmancipateMutExt):
|
||||
//! A trait to convert `Ref<B, T>` into a borrowed mutable `Ref<&mut [u8], T>`.
|
||||
//! - [`ZerocopySliceExt`](crate::zerocopy::ZerocopySliceExt): Extension methods
|
||||
//! for parsing byte slices into zero-copy references.
|
||||
//! - [`ZerocopyMutSliceExt`](crate::zerocopy::ZerocopyMutSliceExt):
|
||||
//! Extension methods for parsing and zeroizing byte slices into zero-copy
|
||||
//! references.
|
||||
|
||||
mod ref_maker;
|
||||
mod zerocopy_ref_ext;
|
||||
|
||||
@@ -61,7 +61,7 @@ impl<B, T> RefMaker<B, T> {
|
||||
}
|
||||
|
||||
/// Returns the size in bytes required by the target type `T`.
|
||||
/// This is currently defined as [std::mem::size_of] of `T`.
|
||||
/// This is currently defined as [`std::mem::size_of::<T>`] of `T`.
|
||||
pub const fn target_size() -> usize {
|
||||
std::mem::size_of::<T>()
|
||||
}
|
||||
@@ -109,15 +109,14 @@ impl<B: ByteSlice, T> RefMaker<B, T> {
|
||||
/// let bytes: &[u8] = &[0x01, 0x02, 0x03];
|
||||
/// let parse_error = RefMaker::<_, Data>::new(bytes).parse()
|
||||
/// .expect_err("Should error");
|
||||
/// assert_eq!(format!("{:?}", parse_error),
|
||||
/// assert_eq!(parse_error.to_string(),
|
||||
/// "Buffer is undersized at 3 bytes (need 4 bytes)!");
|
||||
///
|
||||
/// // errors if the byte buffer is misaligned
|
||||
/// let bytes = [1u8, 2, 3, 4, 5, 6, 7, 8];
|
||||
/// let parse_error = RefMaker::<_, Data>::new(&bytes[1..5]).parse()
|
||||
/// .expect_err("Should error");
|
||||
/// assert_eq!(format!("{:?}", parse_error),
|
||||
/// "Parser error!");
|
||||
/// assert_eq!(parse_error.to_string(), "Parser error!");
|
||||
/// ```
|
||||
pub fn parse(self) -> anyhow::Result<Ref<B, T>> {
|
||||
self.ensure_fit()?;
|
||||
|
||||
@@ -8,8 +8,7 @@ use zerocopy::{ByteSlice, ByteSliceMut, Ref};
|
||||
/// This can be useful when you need a reference that is tied to a slice rather
|
||||
/// than the original buffer type `B`.
|
||||
///
|
||||
/// Note: This trait is implemented to [Ref](zerocopy::Ref) of byte slices
|
||||
/// (`&[u8]`).
|
||||
/// Note: This trait is implemented to [`Ref`] of byte slices (`&[u8]`).
|
||||
pub trait ZerocopyEmancipateExt<B, T> {
|
||||
/// Converts this reference into a reference backed by a plain byte slice.
|
||||
///
|
||||
@@ -36,7 +35,7 @@ pub trait ZerocopyEmancipateExt<B, T> {
|
||||
///
|
||||
/// Similar to [`ZerocopyEmancipateExt`], but for mutable references.
|
||||
///
|
||||
/// Note: this trait is implemented to [Ref](zerocopy::Ref) of mutable byte
|
||||
/// Note: this trait is implemented to [`Ref`] of mutable byte
|
||||
/// slices (`&mut [u8]`).
|
||||
pub trait ZerocopyEmancipateMutExt<B, T> {
|
||||
/// Converts this reference into a mutable reference backed by a plain
|
||||
|
||||
@@ -7,7 +7,7 @@ use super::RefMaker;
|
||||
|
||||
/// Extension trait for performing zero-copy parsing operations on byte slices.
|
||||
///
|
||||
/// This trait adds methods for creating [`Ref`](zerocopy::Ref) references from
|
||||
/// This trait adds methods for creating [`Ref`] references from
|
||||
/// slices by using the [`RefMaker`] type internally.
|
||||
pub trait ZerocopySliceExt: Sized + ByteSlice {
|
||||
/// Creates a new `RefMaker` for the given slice.
|
||||
@@ -58,7 +58,7 @@ pub trait ZerocopySliceExt: Sized + ByteSlice {
|
||||
|
||||
/// Parses a prefix of the slice into a zero-copy reference.
|
||||
///
|
||||
/// Uses only the first [std::mem::size_of::<T>()] bytes of `T`.
|
||||
/// Uses only the first [`std::mem::size_of::<T>()`] bytes of `T`.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
@@ -86,7 +86,7 @@ pub trait ZerocopySliceExt: Sized + ByteSlice {
|
||||
|
||||
/// Parses a suffix of the slice into a zero-copy reference.
|
||||
///
|
||||
/// Uses only the last [std::mem::size_of::<T>()] bytes of `T`.
|
||||
/// Uses only the last [`std::mem::size_of::<T>()`] bytes of `T`.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user