@@ -1713,8 +1713,8 @@ pub unsafe trait TryFromBytes {
17131713 /// use zerocopy::*;
17141714 /// # use zerocopy_derive::*;
17151715 ///
1716- /// #[derive(TryFromBytes, KnownLayout)]
1717- /// #[repr(C)]
1716+ /// #[derive(TryFromBytes, IntoBytes, KnownLayout)]
1717+ /// #[repr(C, packed )]
17181718 /// struct ZSTy {
17191719 /// leading_sized: [u8; 2],
17201720 /// trailing_dst: [()],
@@ -1731,17 +1731,17 @@ pub unsafe trait TryFromBytes {
17311731 /// # use zerocopy_derive::*;
17321732 ///
17331733 /// // The only valid value of this type is the byte `0xC0`
1734- /// #[derive(TryFromBytes, KnownLayout)]
1734+ /// #[derive(TryFromBytes, IntoBytes, KnownLayout)]
17351735 /// #[repr(u8)]
17361736 /// enum C0 { xC0 = 0xC0 }
17371737 ///
17381738 /// // The only valid value of this type is the bytes `0xC0C0`.
1739- /// #[derive(TryFromBytes, KnownLayout)]
1739+ /// #[derive(TryFromBytes, IntoBytes, KnownLayout)]
17401740 /// #[repr(C)]
17411741 /// struct C0C0(C0, C0);
17421742 ///
1743- /// #[derive(TryFromBytes, KnownLayout)]
1744- /// #[repr(C)]
1743+ /// #[derive(TryFromBytes, IntoBytes, KnownLayout)]
1744+ /// #[repr(C, packed )]
17451745 /// struct Packet {
17461746 /// magic_number: C0C0,
17471747 /// mug_size: u8,
@@ -1769,7 +1769,7 @@ pub unsafe trait TryFromBytes {
17691769 #[ inline]
17701770 fn try_mut_from_bytes ( bytes : & mut [ u8 ] ) -> Result < & mut Self , TryCastError < & mut [ u8 ] , Self > >
17711771 where
1772- Self : KnownLayout ,
1772+ Self : KnownLayout + IntoBytes ,
17731773 {
17741774 static_assert_dst_is_not_zst ! ( Self ) ;
17751775 match Ptr :: from_mut ( bytes) . try_cast_into_no_leftover :: < Self , BecauseExclusive > ( None ) {
@@ -1821,8 +1821,8 @@ pub unsafe trait TryFromBytes {
18211821 /// use zerocopy::*;
18221822 /// # use zerocopy_derive::*;
18231823 ///
1824- /// #[derive(TryFromBytes, KnownLayout)]
1825- /// #[repr(C)]
1824+ /// #[derive(TryFromBytes, IntoBytes, KnownLayout)]
1825+ /// #[repr(C, packed )]
18261826 /// struct ZSTy {
18271827 /// leading_sized: [u8; 2],
18281828 /// trailing_dst: [()],
@@ -1839,17 +1839,17 @@ pub unsafe trait TryFromBytes {
18391839 /// # use zerocopy_derive::*;
18401840 ///
18411841 /// // The only valid value of this type is the byte `0xC0`
1842- /// #[derive(TryFromBytes, KnownLayout)]
1842+ /// #[derive(TryFromBytes, IntoBytes, KnownLayout)]
18431843 /// #[repr(u8)]
18441844 /// enum C0 { xC0 = 0xC0 }
18451845 ///
18461846 /// // The only valid value of this type is the bytes `0xC0C0`.
1847- /// #[derive(TryFromBytes, KnownLayout)]
1847+ /// #[derive(TryFromBytes, IntoBytes, KnownLayout)]
18481848 /// #[repr(C)]
18491849 /// struct C0C0(C0, C0);
18501850 ///
1851- /// #[derive(TryFromBytes, KnownLayout)]
1852- /// #[repr(C)]
1851+ /// #[derive(TryFromBytes, IntoBytes, KnownLayout)]
1852+ /// #[repr(C, packed )]
18531853 /// struct Packet {
18541854 /// magic_number: C0C0,
18551855 /// mug_size: u8,
@@ -1882,7 +1882,7 @@ pub unsafe trait TryFromBytes {
18821882 source : & mut [ u8 ] ,
18831883 ) -> Result < ( & mut Self , & mut [ u8 ] ) , TryCastError < & mut [ u8 ] , Self > >
18841884 where
1885- Self : KnownLayout ,
1885+ Self : KnownLayout + IntoBytes ,
18861886 {
18871887 static_assert_dst_is_not_zst ! ( Self ) ;
18881888 try_mut_from_prefix_suffix ( source, CastType :: Prefix , None )
@@ -1916,8 +1916,8 @@ pub unsafe trait TryFromBytes {
19161916 /// use zerocopy::*;
19171917 /// # use zerocopy_derive::*;
19181918 ///
1919- /// #[derive(TryFromBytes, KnownLayout)]
1920- /// #[repr(C)]
1919+ /// #[derive(TryFromBytes, IntoBytes, KnownLayout)]
1920+ /// #[repr(C, packed )]
19211921 /// struct ZSTy {
19221922 /// leading_sized: u16,
19231923 /// trailing_dst: [()],
@@ -1934,17 +1934,17 @@ pub unsafe trait TryFromBytes {
19341934 /// # use zerocopy_derive::*;
19351935 ///
19361936 /// // The only valid value of this type is the byte `0xC0`
1937- /// #[derive(TryFromBytes, KnownLayout)]
1937+ /// #[derive(TryFromBytes, IntoBytes, KnownLayout)]
19381938 /// #[repr(u8)]
19391939 /// enum C0 { xC0 = 0xC0 }
19401940 ///
19411941 /// // The only valid value of this type is the bytes `0xC0C0`.
1942- /// #[derive(TryFromBytes, KnownLayout)]
1942+ /// #[derive(TryFromBytes, IntoBytes, KnownLayout)]
19431943 /// #[repr(C)]
19441944 /// struct C0C0(C0, C0);
19451945 ///
1946- /// #[derive(TryFromBytes, KnownLayout)]
1947- /// #[repr(C)]
1946+ /// #[derive(TryFromBytes, IntoBytes, KnownLayout)]
1947+ /// #[repr(C, packed )]
19481948 /// struct Packet {
19491949 /// magic_number: C0C0,
19501950 /// mug_size: u8,
@@ -1977,7 +1977,7 @@ pub unsafe trait TryFromBytes {
19771977 source : & mut [ u8 ] ,
19781978 ) -> Result < ( & mut [ u8 ] , & mut Self ) , TryCastError < & mut [ u8 ] , Self > >
19791979 where
1980- Self : KnownLayout ,
1980+ Self : KnownLayout + IntoBytes ,
19811981 {
19821982 static_assert_dst_is_not_zst ! ( Self ) ;
19831983 try_mut_from_prefix_suffix ( source, CastType :: Suffix , None ) . map ( swap)
@@ -2286,17 +2286,17 @@ pub unsafe trait TryFromBytes {
22862286 /// # use zerocopy_derive::*;
22872287 ///
22882288 /// // The only valid value of this type is the byte `0xC0`
2289- /// #[derive(TryFromBytes, KnownLayout)]
2289+ /// #[derive(TryFromBytes, IntoBytes, KnownLayout)]
22902290 /// #[repr(u8)]
22912291 /// enum C0 { xC0 = 0xC0 }
22922292 ///
22932293 /// // The only valid value of this type is the bytes `0xC0C0`.
2294- /// #[derive(TryFromBytes, KnownLayout)]
2294+ /// #[derive(TryFromBytes, IntoBytes, KnownLayout)]
22952295 /// #[repr(C)]
22962296 /// struct C0C0(C0, C0);
22972297 ///
2298- /// #[derive(TryFromBytes, KnownLayout)]
2299- /// #[repr(C)]
2298+ /// #[derive(TryFromBytes, IntoBytes, KnownLayout)]
2299+ /// #[repr(C, packed )]
23002300 /// struct Packet {
23012301 /// magic_number: C0C0,
23022302 /// mug_size: u8,
@@ -2330,8 +2330,8 @@ pub unsafe trait TryFromBytes {
23302330 /// use zerocopy::*;
23312331 /// # use zerocopy_derive::*;
23322332 ///
2333- /// #[derive(TryFromBytes, KnownLayout)]
2334- /// #[repr(C)]
2333+ /// #[derive(TryFromBytes, IntoBytes, KnownLayout)]
2334+ /// #[repr(C, packed )]
23352335 /// struct ZSTy {
23362336 /// leading_sized: NonZeroU16,
23372337 /// trailing_dst: [()],
@@ -2351,7 +2351,7 @@ pub unsafe trait TryFromBytes {
23512351 count : usize ,
23522352 ) -> Result < & mut Self , TryCastError < & mut [ u8 ] , Self > >
23532353 where
2354- Self : KnownLayout < PointerMetadata = usize > ,
2354+ Self : KnownLayout < PointerMetadata = usize > + IntoBytes ,
23552355 {
23562356 match Ptr :: from_mut ( source) . try_cast_into_no_leftover :: < Self , BecauseExclusive > ( Some ( count) )
23572357 {
@@ -2397,17 +2397,17 @@ pub unsafe trait TryFromBytes {
23972397 /// # use zerocopy_derive::*;
23982398 ///
23992399 /// // The only valid value of this type is the byte `0xC0`
2400- /// #[derive(TryFromBytes, KnownLayout)]
2400+ /// #[derive(TryFromBytes, IntoBytes, KnownLayout)]
24012401 /// #[repr(u8)]
24022402 /// enum C0 { xC0 = 0xC0 }
24032403 ///
24042404 /// // The only valid value of this type is the bytes `0xC0C0`.
2405- /// #[derive(TryFromBytes, KnownLayout)]
2405+ /// #[derive(TryFromBytes, IntoBytes, KnownLayout)]
24062406 /// #[repr(C)]
24072407 /// struct C0C0(C0, C0);
24082408 ///
2409- /// #[derive(TryFromBytes, KnownLayout)]
2410- /// #[repr(C)]
2409+ /// #[derive(TryFromBytes, IntoBytes, KnownLayout)]
2410+ /// #[repr(C, packed )]
24112411 /// struct Packet {
24122412 /// magic_number: C0C0,
24132413 /// mug_size: u8,
@@ -2443,8 +2443,8 @@ pub unsafe trait TryFromBytes {
24432443 /// use zerocopy::*;
24442444 /// # use zerocopy_derive::*;
24452445 ///
2446- /// #[derive(TryFromBytes, KnownLayout)]
2447- /// #[repr(C)]
2446+ /// #[derive(TryFromBytes, IntoBytes, KnownLayout)]
2447+ /// #[repr(C, packed )]
24482448 /// struct ZSTy {
24492449 /// leading_sized: NonZeroU16,
24502450 /// trailing_dst: [()],
@@ -2464,7 +2464,7 @@ pub unsafe trait TryFromBytes {
24642464 count : usize ,
24652465 ) -> Result < ( & mut Self , & mut [ u8 ] ) , TryCastError < & mut [ u8 ] , Self > >
24662466 where
2467- Self : KnownLayout < PointerMetadata = usize > ,
2467+ Self : KnownLayout < PointerMetadata = usize > + IntoBytes ,
24682468 {
24692469 try_mut_from_prefix_suffix ( source, CastType :: Prefix , Some ( count) )
24702470 }
@@ -2492,17 +2492,17 @@ pub unsafe trait TryFromBytes {
24922492 /// # use zerocopy_derive::*;
24932493 ///
24942494 /// // The only valid value of this type is the byte `0xC0`
2495- /// #[derive(TryFromBytes, KnownLayout)]
2495+ /// #[derive(TryFromBytes, IntoBytes, KnownLayout)]
24962496 /// #[repr(u8)]
24972497 /// enum C0 { xC0 = 0xC0 }
24982498 ///
24992499 /// // The only valid value of this type is the bytes `0xC0C0`.
2500- /// #[derive(TryFromBytes, KnownLayout)]
2500+ /// #[derive(TryFromBytes, IntoBytes, KnownLayout)]
25012501 /// #[repr(C)]
25022502 /// struct C0C0(C0, C0);
25032503 ///
2504- /// #[derive(TryFromBytes, KnownLayout)]
2505- /// #[repr(C)]
2504+ /// #[derive(TryFromBytes, IntoBytes, KnownLayout)]
2505+ /// #[repr(C, packed )]
25062506 /// struct Packet {
25072507 /// magic_number: C0C0,
25082508 /// mug_size: u8,
@@ -2538,8 +2538,8 @@ pub unsafe trait TryFromBytes {
25382538 /// use zerocopy::*;
25392539 /// # use zerocopy_derive::*;
25402540 ///
2541- /// #[derive(TryFromBytes, KnownLayout)]
2542- /// #[repr(C)]
2541+ /// #[derive(TryFromBytes, IntoBytes, KnownLayout)]
2542+ /// #[repr(C, packed )]
25432543 /// struct ZSTy {
25442544 /// leading_sized: NonZeroU16,
25452545 /// trailing_dst: [()],
@@ -2559,7 +2559,7 @@ pub unsafe trait TryFromBytes {
25592559 count : usize ,
25602560 ) -> Result < ( & mut [ u8 ] , & mut Self ) , TryCastError < & mut [ u8 ] , Self > >
25612561 where
2562- Self : KnownLayout < PointerMetadata = usize > ,
2562+ Self : KnownLayout < PointerMetadata = usize > + IntoBytes ,
25632563 {
25642564 try_mut_from_prefix_suffix ( source, CastType :: Suffix , Some ( count) ) . map ( swap)
25652565 }
@@ -2771,7 +2771,7 @@ fn try_ref_from_prefix_suffix<T: TryFromBytes + KnownLayout + Immutable + ?Sized
27712771}
27722772
27732773#[ inline( always) ]
2774- fn try_mut_from_prefix_suffix < T : TryFromBytes + KnownLayout + ?Sized > (
2774+ fn try_mut_from_prefix_suffix < T : IntoBytes + TryFromBytes + KnownLayout + ?Sized > (
27752775 candidate : & mut [ u8 ] ,
27762776 cast_type : CastType ,
27772777 meta : Option < T :: PointerMetadata > ,
0 commit comments