From ef4f550abcc29c957ed3dc2699d84a7e01ff0ce4 Mon Sep 17 00:00:00 2001 From: Amin Faez Date: Sun, 15 Dec 2024 13:05:55 +0100 Subject: [PATCH] docs(util): fix doc reference in the zerocopy module --- util/src/zerocopy/mod.rs | 21 +++++++++++---------- util/src/zerocopy/ref_maker.rs | 7 +++---- util/src/zerocopy/zerocopy_ref_ext.rs | 5 ++--- util/src/zerocopy/zerocopy_slice_ext.rs | 6 +++--- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/util/src/zerocopy/mod.rs b/util/src/zerocopy/mod.rs index 27ed31855..9711fe6bd 100644 --- a/util/src/zerocopy/mod.rs +++ b/util/src/zerocopy/mod.rs @@ -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` into a borrowed -//! `Ref<&[u8], T>`. -//! - [`ZerocopyEmancipateMutExt`]: A trait to convert `Ref` 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` into a borrowed `Ref<&[u8], T>`. +//! - [`ZerocopyEmancipateMutExt`](crate::zerocopy::ZerocopyEmancipateMutExt): +//! A trait to convert `Ref` 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; diff --git a/util/src/zerocopy/ref_maker.rs b/util/src/zerocopy/ref_maker.rs index 3fcb0edf5..f0c46edd3 100644 --- a/util/src/zerocopy/ref_maker.rs +++ b/util/src/zerocopy/ref_maker.rs @@ -61,7 +61,7 @@ impl RefMaker { } /// 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::`] of `T`. pub const fn target_size() -> usize { std::mem::size_of::() } @@ -109,15 +109,14 @@ impl RefMaker { /// 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> { self.ensure_fit()?; diff --git a/util/src/zerocopy/zerocopy_ref_ext.rs b/util/src/zerocopy/zerocopy_ref_ext.rs index aa50b1143..fa3c1b3cc 100644 --- a/util/src/zerocopy/zerocopy_ref_ext.rs +++ b/util/src/zerocopy/zerocopy_ref_ext.rs @@ -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 { /// Converts this reference into a reference backed by a plain byte slice. /// @@ -36,7 +35,7 @@ pub trait ZerocopyEmancipateExt { /// /// 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 { /// Converts this reference into a mutable reference backed by a plain diff --git a/util/src/zerocopy/zerocopy_slice_ext.rs b/util/src/zerocopy/zerocopy_slice_ext.rs index c6ab1ca2e..3dd539324 100644 --- a/util/src/zerocopy/zerocopy_slice_ext.rs +++ b/util/src/zerocopy/zerocopy_slice_ext.rs @@ -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::()] bytes of `T`. + /// Uses only the first [`std::mem::size_of::()`] 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::()] bytes of `T`. + /// Uses only the last [`std::mem::size_of::()`] bytes of `T`. /// /// # Errors ///