Skip to content

Commit

Permalink
Make TryFromBytes a super-trait of FromZeros
Browse files Browse the repository at this point in the history
Makes progress on #5
  • Loading branch information
joshlf committed Feb 27, 2024
1 parent 978b400 commit 2838af0
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1427,7 +1427,7 @@ pub unsafe trait TryFromBytes {
doc = concat!("[derive]: https://docs.rs/zerocopy/", env!("CARGO_PKG_VERSION"), "/zerocopy/derive.FromZeros.html"),
doc = concat!("[derive-analysis]: https://docs.rs/zerocopy/", env!("CARGO_PKG_VERSION"), "/zerocopy/derive.FromZeros.html#analysis"),
)]
pub unsafe trait FromZeros {
pub unsafe trait FromZeros: TryFromBytes {
// The `Self: Sized` bound makes it so that `FromZeros` is still object
// safe.
#[doc(hidden)]
Expand Down Expand Up @@ -3703,8 +3703,10 @@ safety_comment! {
///
/// `UnsafeCell<T>`` has the same in-memory representation as its inner
/// type `T`.
unsafe_impl!(T: ?Sized + FromZeros => FromZeros for UnsafeCell<T>);
unsafe_impl!(T: ?Sized + FromBytes => FromBytes for UnsafeCell<T>);
///
/// TODO(#5): Implement `FromZeros` and `FromBytes` when `T: ?Sized`.
unsafe_impl!(T: FromZeros => FromZeros for UnsafeCell<T>);
unsafe_impl!(T: FromBytes => FromBytes for UnsafeCell<T>);
unsafe_impl!(T: ?Sized + IntoBytes => IntoBytes for UnsafeCell<T>);
unsafe_impl!(T: ?Sized + Unaligned => Unaligned for UnsafeCell<T>);
assert_unaligned!(UnsafeCell<()>, UnsafeCell<u8>);
Expand Down Expand Up @@ -7149,8 +7151,6 @@ mod tests {
#[test]
fn test_object_safety() {
fn _takes_no_cell(_: &dyn NoCell) {}
fn _takes_from_zeros(_: &dyn FromZeros) {}
fn _takes_from_bytes(_: &dyn FromBytes) {}
fn _takes_unaligned(_: &dyn Unaligned) {}
}

Expand Down

0 comments on commit 2838af0

Please sign in to comment.