Skip to content

Commit

Permalink
FlexZeroSlize: implement Eq and PartialEq by hand (#2834)
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung authored Nov 18, 2022
1 parent cec3f13 commit 5487653
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion utils/zerovec/src/flexzerovec/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const USIZE_WIDTH: usize = mem::size_of::<usize>();

/// A zero-copy "slice" that efficiently represents `[usize]`.
#[repr(packed)]
#[derive(Eq, PartialEq)]
pub struct FlexZeroSlice {
// Hard Invariant: 1 <= width <= USIZE_WIDTH (which is target_pointer_width)
// Soft Invariant: width == the width of the largest element
Expand All @@ -23,6 +22,13 @@ pub struct FlexZeroSlice {
data: [u8],
}

impl PartialEq for FlexZeroSlice {
fn eq(&self, other: &Self) -> bool {
self.width == other.width && self.data == other.data
}
}
impl Eq for FlexZeroSlice {}

/// Helper function to decode a little-endian "chunk" (byte slice of a specific length)
/// into a `usize`. We cannot call `usize::from_le_bytes` directly because that function
/// requires the high bits to be set to 0.
Expand Down

0 comments on commit 5487653

Please sign in to comment.