Skip to content

Version 0.11.0

Compare
Choose a tag to compare
@csnover csnover released this 05 Feb 02:31
· 110 commits to master since this release
5035d89

Breaking changes

  • Enums variants using #[br(magic)] with mixed data types (i.e. enum Foo { #[br(magic(0_u8))] A, #[br(magic(1_i16))] B }) will now always parse top-to-bottom. Previously, variants would be parsed in groups by type. To maximise performance when parsing enums with mixed magic types, make sure variants with the same magic data type are contiguous. (Thanks, @MrNbaYoh!)
  • The BinrwNamedArgs macro and trait have been renamed to NamedArgs.
  • The ReadOptions::offset field has been moved and is now a named argument specific to the FilePtr type. The #[br(offset)] and #[br(offset_after)] directives will continue to work without any change, but manual uses of FilePtr must now pass the offset in arguments instead of options.
  • ReadOptions and WriteOptions have been removed and replaced with a single Endian parameter.
  • The Args associated type now takes a lifetime to support borrowed arguments. Custom helper functions that don’t need to support borrowed arguments can use the 'static lifetime to maintain the previous behaviour.

New features

  • The #[br(dbg)] directive can be used for quick and dirty debugging output to stderr. (Thanks, @Swiftb0y!) (#50, #162)
  • The args_iter helper can be used for parsing any field where each item is parsed using a value from another iterator as an argument (e.g. an object containing a list of header entries, followed by a list of body entries, where each body entry requires data from the corresponding header entry to be parsed.)
  • The TakeSeek reader adapter is a seekable version of the std::io::Take adapter. Use it by importing the TakeSeekExt trait and calling take_seek on any Read + Seek stream.
  • The #[binrw::parser] and #[binrw::writer] attributes simplify the creation of functions compatible with the parse_with and write_with directives.
  • The #[brw(try_calc)] directive adds a fallible version of the existing calc directive.
  • Add directives for accessing and remapping streams by @csnover in #174 (#[brw(map_stream)])

Enhancements

  • It is now possible to use references in imports/arguments.
  • Rendering of errors can now be controlled using the verbose-backtrace crate feature (enabled by default). Disabling this feature removes extra decorations, ANSI codes, and source text from the built-in error formatting.
  • The no-std implementation of Cursor now overrides Seek::stream_position for improved performance using that API.
  • More useful error messages are now given when an args directive is missing from a field that requires it. (#67, #76)
  • Combining #[binread] and #[binwrite] on a struct or enum is now equivalent to just using #[binrw]. Previously, this was an error.
  • Assertion failures without explicit error messages in #[br(assert)] directives now cause clearer error messages that explicitly state that an assertion failed. Previously, only the expression that failed to assert was given in the output.

Bug fixes

  • The no-std implementation of Cursor now actually seeks when using SeekFrom::End.
  • End-of-file I/O errors are now correctly detected in all cases. (#125)
  • #[br(try)] now only constructs a default value when parsing actually fails.
  • Errors in assert, count, offset, offset_after, and parse_with directives now point correctly at the source of the error.