Skip to content

Commit

Permalink
Inline everything
Browse files Browse the repository at this point in the history
  • Loading branch information
wcampbell0x2a committed Dec 28, 2023
1 parent 1f192c7 commit dbb3849
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions deku-derive/src/macros/deku_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ fn emit_struct(input: &DekuData) -> Result<TokenStream, syn::Error> {

tokens.extend(quote! {
impl #imp ::#crate_::DekuReader<#lifetime, #ctx_types> for #ident #wher {
#[inline(always)]
fn from_reader_with_ctx<R: ::#crate_::no_std_io::Read>(__deku_reader: &mut ::#crate_::reader::Reader<R>, #ctx_arg) -> core::result::Result<Self, ::#crate_::DekuError> {
#read_body
}
Expand Down
10 changes: 10 additions & 0 deletions deku-derive/src/macros/deku_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ fn emit_struct(input: &DekuData) -> Result<TokenStream, syn::Error> {
impl #imp core::convert::TryFrom<#ident> for ::#crate_::bitvec::BitVec<u8, ::#crate_::bitvec::Msb0> #wher {
type Error = ::#crate_::DekuError;

#[inline(always)]
fn try_from(input: #ident) -> core::result::Result<Self, Self::Error> {
input.to_bits()
}
Expand All @@ -59,6 +60,7 @@ fn emit_struct(input: &DekuData) -> Result<TokenStream, syn::Error> {
impl #imp core::convert::TryFrom<#ident> for Vec<u8> #wher {
type Error = ::#crate_::DekuError;

#[inline(always)]
fn try_from(input: #ident) -> core::result::Result<Self, Self::Error> {
::#crate_::DekuContainerWrite::to_bytes(&input)
}
Expand Down Expand Up @@ -86,6 +88,7 @@ fn emit_struct(input: &DekuData) -> Result<TokenStream, syn::Error> {

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

impl #imp ::#crate_::DekuWriter<#ctx_types> for #ident #wher {
#[allow(unused_variables)]
#[inline(always)]
fn to_writer<W: ::#crate_::no_std_io::Write>(&self, __deku_writer: &mut ::#crate_::writer::Writer<W>, #ctx_arg) -> core::result::Result<(), ::#crate_::DekuError> {
#write_body
}
Expand All @@ -108,6 +112,7 @@ fn emit_struct(input: &DekuData) -> Result<TokenStream, syn::Error> {
tokens.extend(quote! {
impl #imp ::#crate_::DekuWriter for #ident #wher {
#[allow(unused_variables)]
#[inline(always)]
fn to_writer<W: ::#crate_::no_std_io::Write>(&self, __deku_writer: &mut ::#crate_::writer::Writer<W>, _: ()) -> core::result::Result<(), ::#crate_::DekuError> {
#write_body
}
Expand Down Expand Up @@ -242,6 +247,7 @@ fn emit_enum(input: &DekuData) -> Result<TokenStream, syn::Error> {
impl #imp core::convert::TryFrom<#ident> for ::#crate_::bitvec::BitVec<u8, ::#crate_::bitvec::Msb0> #wher {
type Error = ::#crate_::DekuError;

#[inline(always)]
fn try_from(input: #ident) -> core::result::Result<Self, Self::Error> {
input.to_bits()
}
Expand All @@ -250,6 +256,7 @@ fn emit_enum(input: &DekuData) -> Result<TokenStream, syn::Error> {
impl #imp core::convert::TryFrom<#ident> for Vec<u8> #wher {
type Error = ::#crate_::DekuError;

#[inline(always)]
fn try_from(input: #ident) -> core::result::Result<Self, Self::Error> {
::#crate_::DekuContainerWrite::to_bytes(&input)
}
Expand All @@ -276,6 +283,7 @@ fn emit_enum(input: &DekuData) -> Result<TokenStream, syn::Error> {

tokens.extend(quote! {
impl #imp DekuUpdate for #ident #wher {
#[inline(always)]
fn update(&mut self) -> core::result::Result<(), ::#crate_::DekuError> {
#update_use

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

impl #imp ::#crate_::DekuWriter<#ctx_types> for #ident #wher {
#[allow(unused_variables)]
#[inline(always)]
fn to_writer<W: ::#crate_::no_std_io::Write>(&self, __deku_writer: &mut ::#crate_::writer::Writer<W>, #ctx_arg) -> core::result::Result<(), ::#crate_::DekuError> {
#write_body
}
Expand All @@ -301,6 +310,7 @@ fn emit_enum(input: &DekuData) -> Result<TokenStream, syn::Error> {
tokens.extend(quote! {
impl #imp ::#crate_::DekuWriter for #ident #wher {
#[allow(unused_variables)]
#[inline(always)]
fn to_writer<W: ::#crate_::no_std_io::Write>(&self, __deku_writer: &mut ::#crate_::writer::Writer<W>, _: ()) -> core::result::Result<(), ::#crate_::DekuError> {
#write_body
}
Expand Down

0 comments on commit dbb3849

Please sign in to comment.