@@ -93,7 +93,7 @@ derive!(NoCell => derive_no_cell => derive_no_cell_inner);
93
93
derive ! ( TryFromBytes => derive_try_from_bytes => derive_try_from_bytes_inner) ;
94
94
derive ! ( FromZeros => derive_from_zeros => derive_from_zeros_inner) ;
95
95
derive ! ( FromBytes => derive_from_bytes => derive_from_bytes_inner) ;
96
- derive ! ( IntoBytes => derive_as_bytes => derive_as_bytes_inner ) ;
96
+ derive ! ( IntoBytes => derive_into_bytes => derive_into_bytes_inner ) ;
97
97
derive ! ( Unaligned => derive_unaligned => derive_unaligned_inner) ;
98
98
99
99
/// Deprecated: prefer [`FromZeros`] instead.
@@ -104,6 +104,14 @@ pub fn derive_from_zeroes(ts: proc_macro::TokenStream) -> proc_macro::TokenStrea
104
104
derive_from_zeros ( ts)
105
105
}
106
106
107
+ /// Deprecated: prefer [`IntoBytes`] instead.
108
+ #[ deprecated( since = "0.8.0" , note = "`AsBytes` was renamed to `IntoBytes`" ) ]
109
+ #[ doc( hidden) ]
110
+ #[ proc_macro_derive( AsBytes ) ]
111
+ pub fn derive_as_bytes ( ts : proc_macro:: TokenStream ) -> proc_macro:: TokenStream {
112
+ derive_into_bytes ( ts)
113
+ }
114
+
107
115
fn derive_known_layout_inner ( ast : & DeriveInput ) -> proc_macro2:: TokenStream {
108
116
let is_repr_c_struct = match & ast. data {
109
117
Data :: Struct ( ..) => {
@@ -324,11 +332,11 @@ fn derive_from_bytes_inner(ast: &DeriveInput) -> proc_macro2::TokenStream {
324
332
IntoIterator :: into_iter ( [ from_zeros, from_bytes] ) . collect ( )
325
333
}
326
334
327
- fn derive_as_bytes_inner ( ast : & DeriveInput ) -> proc_macro2:: TokenStream {
335
+ fn derive_into_bytes_inner ( ast : & DeriveInput ) -> proc_macro2:: TokenStream {
328
336
match & ast. data {
329
- Data :: Struct ( strct) => derive_as_bytes_struct ( ast, strct) ,
330
- Data :: Enum ( enm) => derive_as_bytes_enum ( ast, enm) ,
331
- Data :: Union ( unn) => derive_as_bytes_union ( ast, unn) ,
337
+ Data :: Struct ( strct) => derive_into_bytes_struct ( ast, strct) ,
338
+ Data :: Enum ( enm) => derive_into_bytes_enum ( ast, enm) ,
339
+ Data :: Union ( unn) => derive_into_bytes_union ( ast, unn) ,
332
340
}
333
341
}
334
342
@@ -568,7 +576,7 @@ fn derive_from_zeros_enum(ast: &DeriveInput, enm: &DataEnum) -> proc_macro2::Tok
568
576
569
577
// We don't actually care what the repr is; we just care that it's one of
570
578
// the allowed ones.
571
- try_or_print ! ( ENUM_FROM_ZEROS_AS_BYTES_CFG . validate_reprs( ast) ) ;
579
+ try_or_print ! ( ENUM_FROM_ZEROS_INTO_BYTES_CFG . validate_reprs( ast) ) ;
572
580
573
581
let has_explicit_zero_discriminant =
574
582
enm. variants . iter ( ) . filter_map ( |v| v. discriminant . as_ref ( ) ) . any ( |( _, e) | {
@@ -687,8 +695,8 @@ fn derive_from_bytes_union(ast: &DeriveInput, unn: &DataUnion) -> proc_macro2::T
687
695
impl_block ( ast, unn, Trait :: FromBytes , FieldBounds :: ALL_SELF , SelfBounds :: None , None , None )
688
696
}
689
697
690
- fn derive_as_bytes_struct ( ast : & DeriveInput , strct : & DataStruct ) -> proc_macro2:: TokenStream {
691
- let reprs = try_or_print ! ( STRUCT_UNION_AS_BYTES_CFG . validate_reprs( ast) ) ;
698
+ fn derive_into_bytes_struct ( ast : & DeriveInput , strct : & DataStruct ) -> proc_macro2:: TokenStream {
699
+ let reprs = try_or_print ! ( STRUCT_UNION_INTO_BYTES_CFG . validate_reprs( ast) ) ;
692
700
let is_transparent = reprs. contains ( & StructRepr :: Transparent ) ;
693
701
let is_packed = reprs. contains ( & StructRepr :: Packed ) ;
694
702
let num_fields = strct. fields ( ) . len ( ) ;
@@ -737,7 +745,7 @@ fn derive_as_bytes_struct(ast: &DeriveInput, strct: &DataStruct) -> proc_macro2:
737
745
impl_block ( ast, strct, Trait :: IntoBytes , field_bounds, SelfBounds :: None , padding_check, None )
738
746
}
739
747
740
- const STRUCT_UNION_AS_BYTES_CFG : Config < StructRepr > = Config {
748
+ const STRUCT_UNION_INTO_BYTES_CFG : Config < StructRepr > = Config {
741
749
// Since `disallowed_but_legal_combinations` is empty, this message will
742
750
// never actually be emitted.
743
751
allowed_combinations_message : r#"IntoBytes requires either a) repr "C" or "transparent" with all fields implementing IntoBytes or, b) repr "packed""# ,
@@ -748,20 +756,20 @@ const STRUCT_UNION_AS_BYTES_CFG: Config<StructRepr> = Config {
748
756
749
757
// An enum is `IntoBytes` if it is field-less and has a defined repr.
750
758
751
- fn derive_as_bytes_enum ( ast : & DeriveInput , enm : & DataEnum ) -> proc_macro2:: TokenStream {
759
+ fn derive_into_bytes_enum ( ast : & DeriveInput , enm : & DataEnum ) -> proc_macro2:: TokenStream {
752
760
if !enm. is_fieldless ( ) {
753
761
return Error :: new_spanned ( ast, "only field-less enums can implement IntoBytes" )
754
762
. to_compile_error ( ) ;
755
763
}
756
764
757
765
// We don't care what the repr is; we only care that it is one of the
758
766
// allowed ones.
759
- try_or_print ! ( ENUM_FROM_ZEROS_AS_BYTES_CFG . validate_reprs( ast) ) ;
767
+ try_or_print ! ( ENUM_FROM_ZEROS_INTO_BYTES_CFG . validate_reprs( ast) ) ;
760
768
impl_block ( ast, enm, Trait :: IntoBytes , FieldBounds :: None , SelfBounds :: None , None , None )
761
769
}
762
770
763
771
#[ rustfmt:: skip]
764
- const ENUM_FROM_ZEROS_AS_BYTES_CFG : Config < EnumRepr > = {
772
+ const ENUM_FROM_ZEROS_INTO_BYTES_CFG : Config < EnumRepr > = {
765
773
use EnumRepr :: * ;
766
774
Config {
767
775
// Since `disallowed_but_legal_combinations` is empty, this message will
@@ -790,14 +798,14 @@ const ENUM_FROM_ZEROS_AS_BYTES_CFG: Config<EnumRepr> = {
790
798
// - `repr(C)`, `repr(transparent)`, or `repr(packed)`
791
799
// - no padding (size of union equals size of each field type)
792
800
793
- fn derive_as_bytes_union ( ast : & DeriveInput , unn : & DataUnion ) -> proc_macro2:: TokenStream {
801
+ fn derive_into_bytes_union ( ast : & DeriveInput , unn : & DataUnion ) -> proc_macro2:: TokenStream {
794
802
// TODO(#10): Support type parameters.
795
803
if !ast. generics . params . is_empty ( ) {
796
804
return Error :: new ( Span :: call_site ( ) , "unsupported on types with type parameters" )
797
805
. to_compile_error ( ) ;
798
806
}
799
807
800
- try_or_print ! ( STRUCT_UNION_AS_BYTES_CFG . validate_reprs( ast) ) ;
808
+ try_or_print ! ( STRUCT_UNION_INTO_BYTES_CFG . validate_reprs( ast) ) ;
801
809
802
810
impl_block (
803
811
ast,
0 commit comments