Skip to content

Commit

Permalink
Add inline to emitted in deku-derive
Browse files Browse the repository at this point in the history
  • Loading branch information
wcampbell0x2a committed Dec 22, 2023
1 parent 404316f commit 0799b60
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 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 Expand Up @@ -412,6 +413,7 @@ fn emit_enum(input: &DekuData) -> Result<TokenStream, syn::Error> {
if let Some(deku_id_type) = deku_id_type {
tokens.extend(quote! {
impl #imp DekuEnumExt<#lifetime, (#deku_id_type)> for #ident #wher {
#[inline(always)]
fn deku_id(&self) -> core::result::Result<(#deku_id_type), DekuError> {
match self {
#(#deku_ids ,)*
Expand Down Expand Up @@ -784,11 +786,13 @@ pub fn emit_container_read(
quote! {
impl #imp ::#crate_::DekuContainerRead<#lifetime> for #ident #wher {
#[allow(non_snake_case)]
#[inline(always)]
fn from_reader<'a, R: ::#crate_::no_std_io::Read>(__deku_input: (&'a mut R, usize)) -> core::result::Result<(usize, Self), ::#crate_::DekuError> {
#from_reader_body
}

#[allow(non_snake_case)]
#[inline(always)]
fn from_bytes(__deku_input: (&#lifetime [u8], usize)) -> core::result::Result<((&#lifetime [u8], usize), Self), ::#crate_::DekuError> {
#from_bytes_body
}
Expand All @@ -808,6 +812,7 @@ pub fn emit_try_from(
impl #imp core::convert::TryFrom<&#lifetime [u8]> for #ident #wher {
type Error = ::#crate_::DekuError;

#[inline(always)]
fn try_from(input: &#lifetime [u8]) -> core::result::Result<Self, Self::Error> {
let total_len = input.len();
let mut cursor = ::#crate_::no_std_io::Cursor::new(input);
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 @@ -59,12 +59,14 @@ 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)
}
}

impl #imp DekuContainerWrite for #ident #wher {
#[inline(always)]
fn to_bytes(&self) -> core::result::Result<Vec<u8>, ::#crate_::DekuError> {
let mut out_buf = vec![];
let mut __deku_writer = ::#crate_::writer::Writer::new(&mut out_buf);
Expand Down Expand Up @@ -105,6 +107,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 @@ -115,6 +118,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 @@ -127,6 +131,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 @@ -263,12 +268,14 @@ 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)
}
}

impl #imp DekuContainerWrite for #ident #wher {
#[inline(always)]
fn to_bytes(&self) -> core::result::Result<Vec<u8>, ::#crate_::DekuError> {
let mut out_buf = vec![];
let mut __deku_writer = ::#crate_::writer::Writer::new(&mut out_buf);
Expand Down Expand Up @@ -308,6 +315,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 @@ -321,6 +329,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 @@ -333,6 +342,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 0799b60

Please sign in to comment.