mirror of
https://github.com/rosenpass/rosenpass.git
synced 2026-02-28 22:43:26 -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:
|
//! It offers the following primary abstractions and traits:
|
||||||
//!
|
//!
|
||||||
//! - [`RefMaker`]: A helper structure for safely creating
|
//! - [`RefMaker`](crate::zerocopy::RefMaker): A helper structure for safely
|
||||||
//! [`Ref`](zerocopy::Ref) references from byte slices.
|
//! creating `zerocopy::Ref` references from byte slices.
|
||||||
//! - [`ZerocopyEmancipateExt`]: A trait to convert `Ref<B, T>` into a borrowed
|
//! - [`ZerocopyEmancipateExt`](crate::zerocopy::ZerocopyEmancipateExt):
|
||||||
//! `Ref<&[u8], T>`.
|
//! A trait to convert `Ref<B, T>` into a borrowed `Ref<&[u8], T>`.
|
||||||
//! - [`ZerocopyEmancipateMutExt`]: A trait to convert `Ref<B, T>` into a
|
//! - [`ZerocopyEmancipateMutExt`](crate::zerocopy::ZerocopyEmancipateMutExt):
|
||||||
//! borrowed mutable `Ref<&mut [u8], T>`.
|
//! A trait to convert `Ref<B, T>` into a borrowed mutable `Ref<&mut [u8], T>`.
|
||||||
//! - [`ZerocopySliceExt`]: Extension methods for parsing byte slices into
|
//! - [`ZerocopySliceExt`](crate::zerocopy::ZerocopySliceExt): Extension methods
|
||||||
//! zero-copy references.
|
//! for parsing byte slices into zero-copy references.
|
||||||
//! - [`ZerocopyMutSliceExt`]: Extension methods for parsing and zeroizing byte
|
//! - [`ZerocopyMutSliceExt`](crate::zerocopy::ZerocopyMutSliceExt):
|
||||||
//! slices into zero-copy references.
|
//! Extension methods for parsing and zeroizing byte slices into zero-copy
|
||||||
|
//! references.
|
||||||
|
|
||||||
mod ref_maker;
|
mod ref_maker;
|
||||||
mod zerocopy_ref_ext;
|
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`.
|
/// 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 {
|
pub const fn target_size() -> usize {
|
||||||
std::mem::size_of::<T>()
|
std::mem::size_of::<T>()
|
||||||
}
|
}
|
||||||
@@ -109,15 +109,14 @@ impl<B: ByteSlice, T> RefMaker<B, T> {
|
|||||||
/// let bytes: &[u8] = &[0x01, 0x02, 0x03];
|
/// let bytes: &[u8] = &[0x01, 0x02, 0x03];
|
||||||
/// let parse_error = RefMaker::<_, Data>::new(bytes).parse()
|
/// let parse_error = RefMaker::<_, Data>::new(bytes).parse()
|
||||||
/// .expect_err("Should error");
|
/// .expect_err("Should error");
|
||||||
/// assert_eq!(format!("{:?}", parse_error),
|
/// assert_eq!(parse_error.to_string(),
|
||||||
/// "Buffer is undersized at 3 bytes (need 4 bytes)!");
|
/// "Buffer is undersized at 3 bytes (need 4 bytes)!");
|
||||||
///
|
///
|
||||||
/// // errors if the byte buffer is misaligned
|
/// // errors if the byte buffer is misaligned
|
||||||
/// let bytes = [1u8, 2, 3, 4, 5, 6, 7, 8];
|
/// let bytes = [1u8, 2, 3, 4, 5, 6, 7, 8];
|
||||||
/// let parse_error = RefMaker::<_, Data>::new(&bytes[1..5]).parse()
|
/// let parse_error = RefMaker::<_, Data>::new(&bytes[1..5]).parse()
|
||||||
/// .expect_err("Should error");
|
/// .expect_err("Should error");
|
||||||
/// assert_eq!(format!("{:?}", parse_error),
|
/// assert_eq!(parse_error.to_string(), "Parser error!");
|
||||||
/// "Parser error!");
|
|
||||||
/// ```
|
/// ```
|
||||||
pub fn parse(self) -> anyhow::Result<Ref<B, T>> {
|
pub fn parse(self) -> anyhow::Result<Ref<B, T>> {
|
||||||
self.ensure_fit()?;
|
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
|
/// This can be useful when you need a reference that is tied to a slice rather
|
||||||
/// than the original buffer type `B`.
|
/// than the original buffer type `B`.
|
||||||
///
|
///
|
||||||
/// Note: This trait is implemented to [Ref](zerocopy::Ref) of byte slices
|
/// Note: This trait is implemented to [`Ref`] of byte slices (`&[u8]`).
|
||||||
/// (`&[u8]`).
|
|
||||||
pub trait ZerocopyEmancipateExt<B, T> {
|
pub trait ZerocopyEmancipateExt<B, T> {
|
||||||
/// Converts this reference into a reference backed by a plain byte slice.
|
/// 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.
|
/// 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]`).
|
/// slices (`&mut [u8]`).
|
||||||
pub trait ZerocopyEmancipateMutExt<B, T> {
|
pub trait ZerocopyEmancipateMutExt<B, T> {
|
||||||
/// Converts this reference into a mutable reference backed by a plain
|
/// 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.
|
/// 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.
|
/// slices by using the [`RefMaker`] type internally.
|
||||||
pub trait ZerocopySliceExt: Sized + ByteSlice {
|
pub trait ZerocopySliceExt: Sized + ByteSlice {
|
||||||
/// Creates a new `RefMaker` for the given slice.
|
/// 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.
|
/// 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
|
/// # Errors
|
||||||
///
|
///
|
||||||
@@ -86,7 +86,7 @@ pub trait ZerocopySliceExt: Sized + ByteSlice {
|
|||||||
|
|
||||||
/// Parses a suffix of the slice into a zero-copy reference.
|
/// 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
|
/// # Errors
|
||||||
///
|
///
|
||||||
|
|||||||
Reference in New Issue
Block a user