Skip to content

Commit

Permalink
Mark auto derived functions
Browse files Browse the repository at this point in the history
* Add automatically_derived to all impl functions in deku-derive
* Motivation: rust-lang/rust#120185
  • Loading branch information
wcampbell0x2a committed Oct 27, 2024
1 parent 59fc760 commit affa54c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions deku-derive/src/macros/deku_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ fn emit_struct(input: &DekuData) -> Result<TokenStream, syn::Error> {
};

tokens.extend(quote! {
#[automatically_derived]
impl #imp ::#crate_::DekuReader<#lifetime, #ctx_types> for #ident #wher {
#[inline]
fn from_reader_with_ctx<R: ::#crate_::no_std_io::Read + ::#crate_::no_std_io::Seek>(__deku_reader: &mut ::#crate_::reader::Reader<R>, #ctx_arg) -> core::result::Result<Self, ::#crate_::DekuError> {
Expand All @@ -175,6 +176,7 @@ fn emit_struct(input: &DekuData) -> Result<TokenStream, syn::Error> {
let read_body = wrap_default_ctx(read_body, &input.ctx, &input.ctx_default);

tokens.extend(quote! {
#[automatically_derived]
impl #imp ::#crate_::DekuReader<#lifetime> for #ident #wher {
#[inline]
fn from_reader_with_ctx<R: ::#crate_::no_std_io::Read + ::#crate_::no_std_io::Seek>(__deku_reader: &mut ::#crate_::reader::Reader<R>, _: ()) -> core::result::Result<Self, ::#crate_::DekuError> {
Expand Down Expand Up @@ -433,6 +435,7 @@ fn emit_enum(input: &DekuData) -> Result<TokenStream, syn::Error> {

tokens.extend(quote! {
#[allow(non_snake_case)]
#[automatically_derived]
impl #imp ::#crate_::DekuReader<#lifetime, #ctx_types> for #ident #wher {
#[inline]
fn from_reader_with_ctx<R: ::#crate_::no_std_io::Read + ::#crate_::no_std_io::Seek>(__deku_reader: &mut ::#crate_::reader::Reader<R>, #ctx_arg) -> core::result::Result<Self, ::#crate_::DekuError> {
Expand All @@ -446,6 +449,7 @@ fn emit_enum(input: &DekuData) -> Result<TokenStream, syn::Error> {

tokens.extend(quote! {
#[allow(non_snake_case)]
#[automatically_derived]
impl #imp ::#crate_::DekuReader<#lifetime> for #ident #wher {
#[inline]
fn from_reader_with_ctx<R: ::#crate_::no_std_io::Read + ::#crate_::no_std_io::Seek>(__deku_reader: &mut ::#crate_::reader::Reader<R>, _: ()) -> core::result::Result<Self, ::#crate_::DekuError> {
Expand All @@ -470,6 +474,7 @@ fn emit_enum(input: &DekuData) -> Result<TokenStream, syn::Error> {
// would need to be appended to #imp
} else {
tokens.extend(quote! {
#[automatically_derived]
impl<'__deku> #imp ::#crate_::DekuEnumExt<#lifetime, (#deku_id_type)> for #ident #wher {
#[inline]
fn deku_id(&self) -> core::result::Result<(#deku_id_type), ::#crate_::DekuError> {
Expand Down Expand Up @@ -973,6 +978,7 @@ pub fn emit_container_read(
) -> TokenStream {
let crate_ = super::get_crate_name();
quote! {
#[automatically_derived]
impl #imp ::#crate_::DekuContainerRead<#lifetime> for #ident #wher {
#[allow(non_snake_case)]
#[inline]
Expand All @@ -998,6 +1004,7 @@ pub fn emit_try_from(
) -> TokenStream {
let crate_ = super::get_crate_name();
quote! {
#[automatically_derived]
impl #imp core::convert::TryFrom<&#lifetime [u8]> for #ident #wher {
type Error = ::#crate_::DekuError;

Expand Down
12 changes: 12 additions & 0 deletions deku-derive/src/macros/deku_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ fn emit_struct(input: &DekuData) -> Result<TokenStream, syn::Error> {
if input.ctx.is_none() || (input.ctx.is_some() && input.ctx_default.is_some()) {
#[cfg(feature = "bits")]
tokens.extend(quote! {
#[automatically_derived]
impl #imp core::convert::TryFrom<#ident> for ::#crate_::bitvec::BitVec<u8, ::#crate_::bitvec::Msb0> #wher {
type Error = ::#crate_::DekuError;

Expand All @@ -105,6 +106,7 @@ fn emit_struct(input: &DekuData) -> Result<TokenStream, syn::Error> {
});

tokens.extend(quote! {
#[automatically_derived]
impl #imp core::convert::TryFrom<#ident> for Vec<u8> #wher {
type Error = ::#crate_::DekuError;

Expand All @@ -114,6 +116,7 @@ fn emit_struct(input: &DekuData) -> Result<TokenStream, syn::Error> {
}
}

#[automatically_derived]
impl #imp ::#crate_::DekuContainerWrite for #ident #wher {}
});
}
Expand All @@ -136,6 +139,7 @@ fn emit_struct(input: &DekuData) -> Result<TokenStream, syn::Error> {
let update_use = check_update_use(&field_updates);

tokens.extend(quote! {
#[automatically_derived]
impl #imp ::#crate_::DekuUpdate for #ident #wher {
#[inline]
fn update(&mut self) -> core::result::Result<(), ::#crate_::DekuError> {
Expand All @@ -146,6 +150,7 @@ fn emit_struct(input: &DekuData) -> Result<TokenStream, syn::Error> {
}
}

#[automatically_derived]
impl #imp ::#crate_::DekuWriter<#ctx_types> for #ident #wher {
#[allow(unused_variables)]
#[inline]
Expand All @@ -159,6 +164,7 @@ fn emit_struct(input: &DekuData) -> Result<TokenStream, syn::Error> {
let write_body = wrap_default_ctx(write_body, &input.ctx, &input.ctx_default);

tokens.extend(quote! {
#[automatically_derived]
impl #imp ::#crate_::DekuWriter for #ident #wher {
#[allow(unused_variables)]
#[inline]
Expand Down Expand Up @@ -300,6 +306,7 @@ fn emit_enum(input: &DekuData) -> Result<TokenStream, syn::Error> {
if input.ctx.is_none() || (input.ctx.is_some() && input.ctx_default.is_some()) {
#[cfg(feature = "bits")]
tokens.extend(quote! {
#[automatically_derived]
impl #imp core::convert::TryFrom<#ident> for ::#crate_::bitvec::BitVec<u8, ::#crate_::bitvec::Msb0> #wher {
type Error = ::#crate_::DekuError;

Expand All @@ -312,6 +319,7 @@ fn emit_enum(input: &DekuData) -> Result<TokenStream, syn::Error> {
});

tokens.extend(quote! {
#[automatically_derived]
impl #imp core::convert::TryFrom<#ident> for Vec<u8> #wher {
type Error = ::#crate_::DekuError;

Expand All @@ -321,6 +329,7 @@ fn emit_enum(input: &DekuData) -> Result<TokenStream, syn::Error> {
}
}

#[automatically_derived]
impl #imp ::#crate_::DekuContainerWrite for #ident #wher {}
});
}
Expand All @@ -341,6 +350,7 @@ fn emit_enum(input: &DekuData) -> Result<TokenStream, syn::Error> {
let update_use = check_update_use(&variant_updates);

tokens.extend(quote! {
#[automatically_derived]
impl #imp ::#crate_::DekuUpdate for #ident #wher {
#[inline]
fn update(&mut self) -> core::result::Result<(), ::#crate_::DekuError> {
Expand All @@ -354,6 +364,7 @@ fn emit_enum(input: &DekuData) -> Result<TokenStream, syn::Error> {
}
}

#[automatically_derived]
impl #imp ::#crate_::DekuWriter<#ctx_types> for #ident #wher {
#[allow(unused_variables)]
#[inline]
Expand All @@ -367,6 +378,7 @@ fn emit_enum(input: &DekuData) -> Result<TokenStream, syn::Error> {
let write_body = wrap_default_ctx(write_body, &input.ctx, &input.ctx_default);

tokens.extend(quote! {
#[automatically_derived]
impl #imp ::#crate_::DekuWriter for #ident #wher {
#[allow(unused_variables)]
#[inline]
Expand Down

0 comments on commit affa54c

Please sign in to comment.