Skip to content

Commit

Permalink
Rename NoCell to Immutable
Browse files Browse the repository at this point in the history
We selected `Immutable` on @rcoh's suggestion that our name for this be a
single, evocative word, like `Send` and `Sync`. As with `Send` and `Sync`,
we do not hope that `Immutable`, on its own, captures the entire semantics
of this trait; the burden of entirely capturing its semantics rests on its
documentation.

We are not overly concerned with the risk of future conflict with Rust. If
and when Rust stabilizes its own version of this trait, we will adjust
zerocopy to use Rust's trait instead.

Closes #994
  • Loading branch information
jswrenn committed Apr 24, 2024
1 parent 22c08d4 commit 6a9586a
Show file tree
Hide file tree
Showing 60 changed files with 744 additions and 730 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ functionality themselves, but are required to call certain methods provided
by the conversion traits:
- `KnownLayout` indicates that zerocopy can reason about certain layout
qualities of a type
- `NoCell` indicates that a type does not contain any `UnsafeCell`s
- `Immutable` indicates that a type does not contain any `UnsafeCell`s
- `Unaligned` indicates that a type's alignment requirement is 1

You should generally derive these marker traits whenever possible.
Expand Down
14 changes: 7 additions & 7 deletions src/byteorder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
//!
//! ```rust,edition2021
//! # #[cfg(feature = "derive")] { // This example uses derives, and won't compile without them
//! use zerocopy::{IntoBytes, FromBytes, KnownLayout, NoCell, Ref, SplitByteSlice, Unaligned};
//! use zerocopy::{IntoBytes, FromBytes, KnownLayout, Immutable, Ref, SplitByteSlice, Unaligned};
//! use zerocopy::byteorder::network_endian::U16;
//!
//! #[derive(FromBytes, IntoBytes, KnownLayout, NoCell, Unaligned)]
//! #[derive(FromBytes, IntoBytes, KnownLayout, Immutable, Unaligned)]
//! #[repr(C)]
//! struct UdpHeader {
//! src_port: U16,
Expand Down Expand Up @@ -378,7 +378,7 @@ example of how it can be used for parsing UDP packets.
[`IntoBytes`]: crate::IntoBytes
[`Unaligned`]: crate::Unaligned"),
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
#[cfg_attr(any(feature = "derive", test), derive(KnownLayout, NoCell, FromBytes, IntoBytes, Unaligned))]
#[cfg_attr(any(feature = "derive", test), derive(KnownLayout, Immutable, FromBytes, IntoBytes, Unaligned))]
#[repr(transparent)]
pub struct $name<O>([u8; $bytes], PhantomData<O>);
}
Expand All @@ -390,9 +390,9 @@ example of how it can be used for parsing UDP packets.
/// SAFETY:
/// `$name<O>` is `repr(transparent)`, and so it has the same layout
/// as its only non-zero field, which is a `u8` array. `u8` arrays
/// are `NoCell`, `TryFromBytes`, `FromZeros`, `FromBytes`,
/// are `Immutable`, `TryFromBytes`, `FromZeros`, `FromBytes`,
/// `IntoBytes`, and `Unaligned`.
impl_or_verify!(O => NoCell for $name<O>);
impl_or_verify!(O => Immutable for $name<O>);
impl_or_verify!(O => TryFromBytes for $name<O>);
impl_or_verify!(O => FromZeros for $name<O>);
impl_or_verify!(O => FromBytes for $name<O>);
Expand Down Expand Up @@ -903,7 +903,7 @@ mod tests {
use compatibility::*;

// A native integer type (u16, i32, etc).
trait Native: Arbitrary + FromBytes + IntoBytes + NoCell + Copy + PartialEq + Debug {
trait Native: Arbitrary + FromBytes + IntoBytes + Immutable + Copy + PartialEq + Debug {
const ZERO: Self;
const MAX_VALUE: Self;

Expand Down Expand Up @@ -948,7 +948,7 @@ mod tests {
}

trait ByteArray:
FromBytes + IntoBytes + NoCell + Copy + AsRef<[u8]> + AsMut<[u8]> + Debug + Default + Eq
FromBytes + IntoBytes + Immutable + Copy + AsRef<[u8]> + AsMut<[u8]> + Debug + Default + Eq
{
/// Invert the order of the bytes in the array.
fn invert(self) -> Self;
Expand Down
8 changes: 4 additions & 4 deletions src/deprecated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use super::*;
impl<B, T> Ref<B, [T]>
where
B: ByteSlice,
T: NoCell,
T: Immutable,
{
#[deprecated(since = "0.8.0", note = "`Ref::new` now supports slices")]
#[doc(hidden)]
Expand All @@ -28,7 +28,7 @@ where
impl<B, T> Ref<B, [T]>
where
B: ByteSlice,
T: Unaligned + NoCell,
T: Unaligned + Immutable,
{
#[deprecated(since = "0.8.0", note = "`Ref::new_unaligned` now supports slices")]
#[doc(hidden)]
Expand All @@ -41,7 +41,7 @@ where
impl<'a, B, T> Ref<B, [T]>
where
B: 'a + IntoByteSlice<'a>,
T: FromBytes + NoCell,
T: FromBytes + Immutable,
{
#[deprecated(since = "0.8.0", note = "`Ref::into_ref` now supports slices")]
#[doc(hidden)]
Expand All @@ -54,7 +54,7 @@ where
impl<'a, B, T> Ref<B, [T]>
where
B: 'a + IntoByteSliceMut<'a>,
T: FromBytes + IntoBytes + NoCell,
T: FromBytes + IntoBytes + Immutable,
{
#[deprecated(since = "0.8.0", note = "`Ref::into_mut` now supports slices")]
#[doc(hidden)]
Expand Down

0 comments on commit 6a9586a

Please sign in to comment.