Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions zerocopy/src/pointer/invariant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,17 @@ pub trait Aliasing: Sealed {

/// The alignment invariant of a [`Ptr`][super::Ptr].
pub trait Alignment: Sealed {
// Name the aliasing parameter directly rather than quantifying over an
// Invariants implementation whose Alignment is Self. Both forms require
// the same pointer guarantees; the tuple avoids a recursive dependency
// between the Alignment and Invariants trait declarations during extraction.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Wrap the comment at the repository limit

This new comment is 81 columns wide, including its prefix, although it can be wrapped without impairing readability. Move during extraction. onto a continuation line to comply with the subtree's 80-column prose convention.

AGENTS.md reference: zerocopy/AGENTS.md:L38-L40

Useful? React with 👍 / 👎.

#[doc(hidden)]
#[must_use]
fn read<T, I, R>(ptr: crate::Ptr<'_, T, I>) -> T
fn read<T, A, R>(ptr: crate::Ptr<'_, T, (A, Self, Safe)>) -> T
where
T: Copy + Read<I::Aliasing, R>,
I: Invariants<Alignment = Self, Validity = Safe>,
I::Aliasing: Reference;
Self: Sized,
T: Copy + Read<A, R>,
A: Reference;
}

/// The validity invariant of a [`Ptr`][super::Ptr].
Expand Down Expand Up @@ -148,11 +152,11 @@ pub enum Unaligned {}

impl Alignment for Unaligned {
#[inline(always)]
fn read<T, I, R>(ptr: crate::Ptr<'_, T, I>) -> T
fn read<T, A, R>(ptr: crate::Ptr<'_, T, (A, Self, Safe)>) -> T
where
T: Copy + Read<I::Aliasing, R>,
I: Invariants<Alignment = Self, Validity = Safe>,
I::Aliasing: Reference,
Self: Sized,
T: Copy + Read<A, R>,
A: Reference,
{
(*ptr.into_unalign().as_ref()).into_inner()
}
Expand All @@ -163,11 +167,11 @@ impl Alignment for Unaligned {
pub enum Aligned {}
impl Alignment for Aligned {
#[inline(always)]
fn read<T, I, R>(ptr: crate::Ptr<'_, T, I>) -> T
fn read<T, A, R>(ptr: crate::Ptr<'_, T, (A, Self, Safe)>) -> T
where
T: Copy + Read<I::Aliasing, R>,
I: Invariants<Alignment = Self, Validity = Safe>,
I::Aliasing: Reference,
Self: Sized,
T: Copy + Read<A, R>,
A: Reference,
{
*ptr.as_ref()
}
Expand Down
2 changes: 1 addition & 1 deletion zerocopy/src/pointer/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ mod _conversions {
T: Copy,
T: Read<I::Aliasing, R>,
{
<I::Alignment as Alignment>::read(self)
<I::Alignment as Alignment>::read(self.unify_invariants())
}

/// Views the value as an aligned reference.
Expand Down
Loading