Releases: jam1garner/binrw
Version 0.14.1
Version 0.14.0
Breaking changes
- In derived
BinWrite
implementations, imported variables are now exposed before field variables, to match the way lexical scoping normally works. If an import and a field have the same name, this will cause the import to be shadowed. Previously, the field would be shadowed.
Enhancements
- Diagnostic output is improved when using
parse_with
andmap
together in an incompatible way.
Bug fixes
- It is now possible to use a mix of generic and concrete types in
BinWrite
derives without triggering a type mismatch error. - It is now possible to use the anonymous lifetime
'_
within nested types inside animport
directive. (#241) - The compiler will no longer panic when
verbose-backtrace
is enabled and a derived type contains a docblock with a completely empty line. (#263) - Generated code will no longer trigger
clippy::unnecessary_fallible_conversions
lints.
Version 0.13.3
Bug fixes
- Using
parse_with
/write_with
,map_stream
, andargs
together will no longer raise an error about incompatible stream types. (#240)
Version 0.13.2
Bug fixes
Using parse_with
with map
/try_map
will no longer raise an error about incompatible types when the types are actually compatible. (#239)
Version 0.13.1
Bug fixes
- Using
stream
directive together withmap_stream
no longer causes a borrowck error. (#236)
Version 0.13.0
Breaking changes
- The stream specified by
map_stream
is now only used when reading the inner value(s) of the field/struct/enum it is applied to. Previously, the mapped stream would also be used for magic, padding, etc. when those directives were also applied to the same field or type, but this caused problems with re-borrowing the stream and made the scope of the directive confusing.
New features
- Helper functions for reading and writing unsigned 24-bit integers have been added.
Bug fixes
- It is now possible to use
map_stream
withcount
without causing a borrowck error. - It is now possible to pass args to a
parse_with
function that is notCopy
without causing a borrowck error. (#185) - It is now possible to derive
BinWrite
on a type whose associatedArgs
type implementsDefault
but is not the unit type. (Thanks, @octylFractal!) - It is now possible to use
PhantomData<T>
withBinWrite
whereT
is notBinWrite
. (Thanks, @DCNick3! #230) - Calling
custom_err
on an error with a backtrace will now correctly return the original custom error. (#228) - Rust compiler and dependency versions have been updated to the correct minimum versions. (#224)
- Calling
Error::custom_err
will now always return the custom error even if there is a backtrace associated with it. (#228) - Using
self
in top-level#[bw]
directives now works as expected. (#232) #[bw(assert)]
now actually emits assertions on enums and data enum variants instead of silently accepting the directive without emitting any code.
Version 0.12.0
Breaking changes
- The default behaviour of
FilePtr
has been changed to always immediately seek to and read the pointed-to value. Helper functions have been added to thefile_ptr
module to support the common case of reading from an offset table. Additional helper functions and types will be added in future releases to improve support for file indirection. - The
BinRead::after_parse
API has been removed since it was rarely used, usually broken by manualBinRead
implementations, and made it impossible to use borrowed values in arguments in some cases. For custom two-pass parsing, one alternative is to create an object that will store data that need to be used during the second pass, pass a mutable reference to that object as an argument toread_options
, add data to that object during the first pass, then use the recorded data from the object to perform the required action for the second pass. deref_now
,offset_after
, andpostprocess_now
have been removed as they were designed to control theafter_parse
API which no longer exists. Any field with aderef_now
orpostprocess_now
directive can simply remove the directive to achieve equivalent functionality. Any struct that usedoffset_after
should reorder the fields so the dependent field is after the offset location.
For more detail on these changes, see #210.
- Selected helper functions are no longer re-exported to the root of the crate. Access these helper functions, plus all the other helper functions that were never re-exported to the root, from the
helpers
module. - Using the undocumented internal variable
this
from anassert
directive is no longer supported. Replacethis
with the supportedself
keyword instead.
New features
- Helper functions for more efficient reading of offset tables have been added to the
file_ptr
module. These helpers can be combined with theseek_before
directive to support both relative and absolute positioning of the pointed-to data. See the documentation for usage information and examples. assert
directives on structs, non-unit enums, and data variants can now access the constructed object using theself
keyword. (Thanks, @octylFractal!) (#219)
Enhancements
Clone
is no longer a required trait for arguments passed toparse_with
functions. (Thanks, @octylFractal!)Clone
is no longer a required trait for arguments passed toBinReaderExt
methods.BinRead
is no longer a required trait for dereferencing a value fromFilePtr
. (#218)map
andtry_map
functions can now mutably borrow values.dbg
now also prints information about any padding and alignment directives on a field.- Various documentation improvements.
Bug fixes
- The
count
directive no longer attempts useless conversions. (Thanks, @poliorcetics!) (#206) dbg
now returns the correct position of a field when usingpad_before
oralign_before
. (#188)- Parser errors are no longer discarded if a stream rewind fails. (#215)
- Implementation details of binrw will no longer cause borrow checker failures when passing borrowed arguments to child objects.
Version 0.11.2
Bug fixes
#[binrw::parser]
and#[binrw::writer]
now correctly handle receiving a single argument (thanks, @octylFractal!)#[br(count)]
now returns an error if the given count is out of range instead of usingunwrap
and panicking (#194)
Version 0.11.0
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 toNamedArgs
. - The
ReadOptions::offset
field has been moved and is now a named argument specific to theFilePtr
type. The#[br(offset)]
and#[br(offset_after)]
directives will continue to work without any change, but manual uses ofFilePtr
must now pass the offset in arguments instead of options. ReadOptions
andWriteOptions
have been removed and replaced with a singleEndian
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 tostderr
. (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 thestd::io::Take
adapter. Use it by importing theTakeSeekExt
trait and callingtake_seek
on anyRead + Seek
stream. - The
#[binrw::parser]
and#[binrw::writer]
attributes simplify the creation of functions compatible with theparse_with
andwrite_with
directives. - The
#[brw(try_calc)]
directive adds a fallible version of the existingcalc
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 overridesSeek::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 usingSeekFrom::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
, andparse_with
directives now point correctly at the source of the error.
Version 0.10.0
Breaking changes
-
The
read_bytes
helper, deprecated since 0.2.0, has been removed. UseVec<u8>
directly. -
The
NullString
andNullWideString
APIs have been rewritten to use only standard Rust traits:before 0.10 as of 0.10 T::from_string(s)
From<String>
orFrom<&str>
s.into_string()
s.to_string()
orDisplay
traits.into_string_lossless()
TryFrom<T> for String
trait -
Two
BinWrite
API functions have been renamed for consistency with theBinRead
API:before 0.10 as of 0.10 BinWrite::write_to(...)
BinWrite::write(...)
BinWrite::write_with_args(...)
BinWrite::write_args(...)
-
The
HasMagic
trait has been renamed tometa::ReadMagic
. -
The
Endian::Native
variant has been removed and replaced by an equivalent constant,Endian::NATIVE
. -
The
Default
implementation forEndian
has been removed. Use an explicit value where needed instead. -
Convenience functions that do not accept a byte order (e.g.
BinRead::read(...)
,BinWrite::write(...)
) are now only callable if the underlying type also implementsmeta::ReadEndian
(for reads) andmeta::WriteEndian
(for writes). This prevents unintentional architecture-specific byte ordering. These new traits are automatically derived for types that specify a byte order and for built-in types that do not have any endianness (e.g.Vec<u8>
).
New features
- The
BufReader
wrapper significantly improves performance when reading from non-memory streams (#141) - The
NoSeek
wrapper enables reading and writing non-seekable streams (#6, #78) - Non-zero integer types are now supported by
BinRead
,BinWrite
, andFilePtr
(#134) - Added performance tips to the documentation (#130)
Enhancements
binread
,binrw
, andbinwrite
attributes are now also part of the binrw prelude- Improved performance reading integer primitives into collections (e.g.
Vec<u32>
) (#129) - The
if
directive is now also supported in#[bw]
attributes (#113, #146) - Tuples can now use any args type that implements
Clone
- Error messages are now clearer when
count
andargs
are incorrectly combined, or when passing the wrong type toargs
(#112) - More impls have been added to the
no_std
implementations of theRead
andWrite
traits to improve feature parity with thestd
implementations - The
Debug
implementations ofNullString
andNullWideString
no longer allocate memory - Documentation has been generally improved (#75, #76, #103, #142)
- Write support is now fully documented
- Enum error handling modes are now documented
- Explicit endian helper functions are now also available on
BinRead
andBinWrite
Bug fixes
- Using
try_map = {closure}
on a struct now generates valid code - Errors in
args
directives now point to the correct location of the problem - The optimised
impl BinWrite for Box<[u8]>
is now actually selected by the compiler - Using named arguments no longer triggers clippy warnings about missing docs (#124)
- Trailing commas no longer cause parsing errors in
binrw::args!
NullString
andWideNullString
types are now correctly marked withEq
- Enum variants no longer sometimes unintentionally inherit directives from the parent enum
- Deriving
BinWrite
on unit structs no longer causes a panic pre_assert
directives now correctly apply to unit enum values- Line numbers in verbose backtraces are now correctly padded when the number of digits in the line number increases