Skip to content
Merged
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
91 changes: 91 additions & 0 deletions src/deprecated.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright 2024 The Fuchsia Authors
//
// Licensed under the 2-Clause BSD License <LICENSE-BSD or
// https://opensource.org/license/bsd-2-clause>, Apache License, Version 2.0
// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
// This file may not be copied, modified, or distributed except according to
// those terms.

//! Deprecated items. These are kept separate so that they don't clutter up
//! other modules.

use super::*;

impl<B, T> Ref<B, [T]>
where
B: ByteSlice,
T: NoCell,
{
#[deprecated(since = "0.8.0", note = "`Ref::new` now supports slices")]
#[doc(hidden)]
#[inline]
pub fn new_slice(bytes: B) -> Option<Ref<B, [T]>> {
Self::new(bytes)
}
}

impl<B, T> Ref<B, [T]>
where
B: ByteSliceMut,
T: NoCell,
{
#[deprecated(since = "0.8.0", note = "`Ref::new_zeroed` now supports slices")]
#[doc(hidden)]
#[inline(always)]
pub fn new_slice_zeroed(bytes: B) -> Option<Ref<B, [T]>> {
Self::new_zeroed(bytes)
}
}

impl<B, T> Ref<B, [T]>
where
B: ByteSlice,
T: Unaligned + NoCell,
{
#[deprecated(since = "0.8.0", note = "`Ref::new_unaligned` now supports slices")]
#[doc(hidden)]
#[inline(always)]
pub fn new_slice_unaligned(bytes: B) -> Option<Ref<B, [T]>> {
Ref::new_unaligned(bytes)
}
}

impl<B, T> Ref<B, [T]>
where
B: ByteSliceMut,
T: Unaligned + NoCell,
{
#[deprecated(since = "0.8.0", note = "`Ref::new_unaligned_zeroed` now supports slices")]
#[doc(hidden)]
#[inline(always)]
pub fn new_slice_unaligned_zeroed(bytes: B) -> Option<Ref<B, [T]>> {
Self::new_unaligned_zeroed(bytes)
}
}

impl<'a, B, T> Ref<B, [T]>
where
B: 'a + IntoByteSlice<'a>,
T: FromBytes + NoCell,
{
#[deprecated(since = "0.8.0", note = "`Ref::into_ref` now supports slices")]
#[doc(hidden)]
#[inline(always)]
pub fn into_slice(self) -> &'a [T] {
self.into_ref()
}
}

impl<'a, B, T> Ref<B, [T]>
where
B: 'a + IntoByteSliceMut<'a>,
T: FromBytes + IntoBytes + NoCell,
{
#[deprecated(since = "0.8.0", note = "`Ref::into_mut` now supports slices")]
#[doc(hidden)]
#[inline(always)]
pub fn into_mut_slice(self) -> &'a mut [T] {
self.into_mut()
}
}
121 changes: 22 additions & 99 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ extern crate self as zerocopy;
mod macros;

pub mod byteorder;
mod deprecated;
#[doc(hidden)]
pub mod macro_util;
#[doc(hidden)]
Expand Down Expand Up @@ -2422,17 +2423,6 @@ pub unsafe trait FromBytes: FromZeros {
.map(|(_, r)| r.into_mut())
}

#[deprecated(since = "0.8.0", note = "`FromBytes::ref_from` now supports slices")]
#[allow(clippy::must_use_candidate)]
#[doc(hidden)]
#[inline]
fn slice_from(bytes: &[u8]) -> Option<&[Self]>
where
Self: Sized + NoCell,
{
<[Self]>::ref_from(bytes)
}

/// Interprets the prefix of the given `bytes` as a `&[Self]` with length
/// equal to `count` without copying.
///
Expand Down Expand Up @@ -2812,6 +2802,17 @@ pub unsafe trait FromBytes: FromZeros {
{
Ref::<_, Unalign<Self>>::new_sized_from_suffix(bytes).map(|(_, r)| r.read().into_inner())
}

#[deprecated(since = "0.8.0", note = "`FromBytes::ref_from` now supports slices")]
#[allow(clippy::must_use_candidate)]
#[doc(hidden)]
#[inline]
fn slice_from(bytes: &[u8]) -> Option<&[Self]>
where
Self: Sized + NoCell,
{
<[Self]>::ref_from(bytes)
}
}

/// Analyzes whether a type is [`IntoBytes`].
Expand Down Expand Up @@ -3133,16 +3134,6 @@ pub unsafe trait IntoBytes {
unsafe { slice::from_raw_parts_mut(slf.cast::<u8>(), len) }
}

#[deprecated(since = "0.8.0", note = "`IntoBytes::as_bytes_mut` was renamed to `as_mut_bytes`")]
#[doc(hidden)]
#[inline]
fn as_bytes_mut(&mut self) -> &mut [u8]
where
Self: FromBytes + NoCell,
{
self.as_mut_bytes()
}

/// Writes a copy of `self` to `bytes`.
///
/// If `bytes.len() != size_of_val(self)`, `write_to` returns `None`.
Expand Down Expand Up @@ -3328,6 +3319,16 @@ pub unsafe trait IntoBytes {
.copy_from_slice(self.as_bytes());
Some(())
}

#[deprecated(since = "0.8.0", note = "`IntoBytes::as_bytes_mut` was renamed to `as_mut_bytes`")]
#[doc(hidden)]
#[inline]
fn as_bytes_mut(&mut self) -> &mut [u8]
where
Self: FromBytes + NoCell,
{
self.as_mut_bytes()
}
}

/// Analyzes whether a type is [`Unaligned`].
Expand Down Expand Up @@ -4978,19 +4979,6 @@ where
}
}

impl<B, T> Ref<B, [T]>
where
B: ByteSlice,
T: NoCell,
{
#[deprecated(since = "0.8.0", note = "`Ref::new` now supports slices")]
#[doc(hidden)]
#[inline]
pub fn new_slice(bytes: B) -> Option<Ref<B, [T]>> {
Self::new(bytes)
}
}

impl<B, T> Ref<B, [T]>
where
B: SplitByteSlice,
Expand Down Expand Up @@ -5138,19 +5126,6 @@ where
}
}

impl<B, T> Ref<B, [T]>
where
B: ByteSliceMut,
T: NoCell,
{
#[deprecated(since = "0.8.0", note = "`Ref::new_zeroed` now supports slices")]
#[doc(hidden)]
#[inline(always)]
pub fn new_slice_zeroed(bytes: B) -> Option<Ref<B, [T]>> {
Self::new_zeroed(bytes)
}
}

impl<B, T> Ref<B, [T]>
where
B: SplitByteSliceMut,
Expand Down Expand Up @@ -5251,19 +5226,6 @@ where
}
}

impl<B, T> Ref<B, [T]>
where
B: ByteSlice,
T: Unaligned + NoCell,
{
#[deprecated(since = "0.8.0", note = "`Ref::new_unaligned` now supports slices")]
#[doc(hidden)]
#[inline(always)]
pub fn new_slice_unaligned(bytes: B) -> Option<Ref<B, [T]>> {
Ref::new_unaligned(bytes)
}
}

impl<B, T> Ref<B, [T]>
where
B: SplitByteSlice,
Expand Down Expand Up @@ -5368,19 +5330,6 @@ where
}
}

impl<B, T> Ref<B, [T]>
where
B: ByteSliceMut,
T: Unaligned + NoCell,
{
#[deprecated(since = "0.8.0", note = "`Ref::new_unaligned_zeroed` now supports slices")]
#[doc(hidden)]
#[inline(always)]
pub fn new_slice_unaligned_zeroed(bytes: B) -> Option<Ref<B, [T]>> {
Self::new_unaligned_zeroed(bytes)
}
}

impl<B, T> Ref<B, [T]>
where
B: SplitByteSliceMut,
Expand Down Expand Up @@ -5482,32 +5431,6 @@ where
}
}

impl<'a, B, T> Ref<B, [T]>
where
B: 'a + IntoByteSlice<'a>,
T: FromBytes + NoCell,
{
#[deprecated(since = "0.8.0", note = "`Ref::into_ref` now supports slices")]
#[doc(hidden)]
#[inline(always)]
pub fn into_slice(self) -> &'a [T] {
self.into_ref()
}
}

impl<'a, B, T> Ref<B, [T]>
where
B: 'a + IntoByteSliceMut<'a>,
T: FromBytes + IntoBytes + NoCell,
{
#[deprecated(since = "0.8.0", note = "`Ref::into_mut` now supports slices")]
#[doc(hidden)]
#[inline(always)]
pub fn into_mut_slice(self) -> &'a mut [T] {
self.into_mut()
}
}

impl<B, T> Ref<B, T>
where
B: ByteSlice,
Expand Down