Skip to content

Commit

Permalink
deku-derive: Add expect to seeking
Browse files Browse the repository at this point in the history
  • Loading branch information
wcampbell0x2a committed Nov 2, 2024
1 parent a8f31d1 commit 7ba5423
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
9 changes: 6 additions & 3 deletions deku-derive/src/macros/deku_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ fn emit_struct(input: &DekuData) -> Result<TokenStream, syn::Error> {
{
use ::#crate_::no_std_io::Seek;
use ::#crate_::no_std_io::SeekFrom;
if let Err(e) = __deku_reader.seek(SeekFrom::Current(i64::try_from(#num).unwrap())) {
let seek_amt = i64::try_from(#num).expect("could not convert into i64");
if let Err(e) = __deku_reader.seek(SeekFrom::Current(seek_amt)) {
return Err(::#crate_::DekuError::Io(e.kind()));
}
}
Expand All @@ -52,7 +53,8 @@ fn emit_struct(input: &DekuData) -> Result<TokenStream, syn::Error> {
{
use ::#crate_::no_std_io::Seek;
use ::#crate_::no_std_io::SeekFrom;
if let Err(e) = __deku_reader.seek(SeekFrom::End(i64::try_from(#num).unwrap())) {
let seek_amt = i64::try_from(#num).expect("could not convert into i64");
if let Err(e) = __deku_reader.seek(SeekFrom::End(seek_amt)) {
return Err(::#crate_::DekuError::Io(e.kind()));
}
}
Expand All @@ -62,7 +64,8 @@ fn emit_struct(input: &DekuData) -> Result<TokenStream, syn::Error> {
{
use ::#crate_::no_std_io::Seek;
use ::#crate_::no_std_io::SeekFrom;
if let Err(e) = __deku_reader.seek(SeekFrom::Start(u64::try_from(#num).unwrap())) {
let seek_amt = u64::try_from(#num).expect("could not convert into u64");
if let Err(e) = __deku_reader.seek(SeekFrom::Start(seek_amt)) {
return Err(::#crate_::DekuError::Io(e.kind()));
}
}
Expand Down
9 changes: 6 additions & 3 deletions deku-derive/src/macros/deku_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ fn emit_struct(input: &DekuData) -> Result<TokenStream, syn::Error> {
{
use ::#crate_::no_std_io::Seek;
use ::#crate_::no_std_io::SeekFrom;
if let Err(e) = __deku_writer.seek(SeekFrom::Current(i64::try_from(#num).unwrap())) {
let seek_amt = i64::try_from(#num).expect("could not convert into i64");
if let Err(e) = __deku_writer.seek(SeekFrom::Current(seek_amt)) {
return Err(::#crate_::DekuError::Io(e.kind()));
}
}
Expand All @@ -43,7 +44,8 @@ fn emit_struct(input: &DekuData) -> Result<TokenStream, syn::Error> {
{
use ::#crate_::no_std_io::Seek;
use ::#crate_::no_std_io::SeekFrom;
if let Err(e) = __deku_writer.seek(SeekFrom::End(i64::try_from(#num).unwrap())) {
let seek_amt = i64::try_from(#num).expect("could not convert into i64");
if let Err(e) = __deku_writer.seek(SeekFrom::End(seek_amt)) {
return Err(::#crate_::DekuError::Io(e.kind()));
}
}
Expand All @@ -53,7 +55,8 @@ fn emit_struct(input: &DekuData) -> Result<TokenStream, syn::Error> {
{
use ::#crate_::no_std_io::Seek;
use ::#crate_::no_std_io::SeekFrom;
if let Err(e) = __deku_writer.seek(SeekFrom::Start(u64::try_from(#num).unwrap())) {
let seek_amt = u64::try_from(#num).expect("could not convert into u64");
if let Err(e) = __deku_writer.seek(SeekFrom::Start(seek_amt)) {
return Err(::#crate_::DekuError::Io(e.kind()));
}
}
Expand Down

0 comments on commit 7ba5423

Please sign in to comment.