jam1garner / binrw

A Rust crate for helping parse and rebuild binary data using ✨macro magic✨.
https://binrw.rs
MIT License
585 stars 35 forks source link

use `expect` so clippy does not complain #194

Closed brxken128 closed 1 year ago

brxken128 commented 1 year ago

Currently, when using #[br(count = x)] above a field in a struct, clippy will complain that unwrap is being used (within the macro). No variation of #[allow()] seemed to silence the problem.

This happens because #![warn(clippy::unwrap_used)] is being used throughout the crate I'm working on - it's annoying but helps catch some (potential) issues, so I figure a fix here will likely be the best solution (and hopefully prevent this issue happening to others, too).

csnover commented 1 year ago

Thank you for the patch and sorry for the delay! Since panicking is a very unpleasant thing to do, I’ve implemented an alternative approach that eliminates any panicking unwrap entirely by returning an error for out-of-range count values instead, in #198. Give it a try and let me know how it works!