diff --git a/binrw/src/attribute/read.rs b/binrw/src/attribute/read.rs index ea6337ba..7aee257b 100644 --- a/binrw/src/attribute/read.rs +++ b/binrw/src/attribute/read.rs @@ -773,7 +773,7 @@ //! ``` //! # use binrw::{prelude::*, io::*, ReadOptions}; //! # use std::collections::HashMap; -//! fn custom_parser(reader: &mut R, ro: &ReadOptions, _: ()) +//! fn custom_parser(mut reader: &mut R, ro: &ReadOptions, _: ()) //! -> BinResult> //! { //! let mut map = HashMap::new(); diff --git a/binrw/src/attribute/write.rs b/binrw/src/attribute/write.rs index 62cf757f..7777c199 100644 --- a/binrw/src/attribute/write.rs +++ b/binrw/src/attribute/write.rs @@ -629,7 +629,7 @@ //! //! ``` //! # use binrw::{prelude::*, io::*, BinWrite, Endian, WriteOptions}; -//! fn custom_writer( +//! fn custom_writer( //! &amount: &u16, //! writer: &mut W, //! _opts: &WriteOptions, diff --git a/binrw/src/binread/impls.rs b/binrw/src/binread/impls.rs index 1453f7e2..01b10f05 100644 --- a/binrw/src/binread/impls.rs +++ b/binrw/src/binread/impls.rs @@ -20,7 +20,7 @@ macro_rules! binread_impl { impl BinRead for $type_name { type Args = (); - fn read_options(reader: &mut R, options: &ReadOptions, _: Self::Args) -> BinResult { + fn read_options(reader: &mut R, options: &ReadOptions, _: Self::Args) -> BinResult { let mut val = [0; core::mem::size_of::<$type_name>()]; let pos = reader.stream_position()?; @@ -71,7 +71,7 @@ macro_rules! binread_nonzero_impl { impl BinRead for $Ty { type Args = (); - fn read_options( + fn read_options( reader: &mut R, options: &ReadOptions, _: Self::Args, @@ -159,7 +159,7 @@ pub struct VecArgs { impl BinRead for Vec { type Args = VecArgs; - fn read_options( + fn read_options( reader: &mut R, options: &ReadOptions, args: Self::Args, @@ -191,7 +191,7 @@ impl BinRead for Vec { args: Self::Args, ) -> BinResult<()> where - R: Read + Seek, + R: Read + Seek + ?Sized, { for val in self.iter_mut() { val.after_parse(reader, ro, args.inner.clone())?; @@ -204,7 +204,7 @@ impl BinRead for Vec { impl BinRead for [B; N] { type Args = B::Args; - fn read_options( + fn read_options( reader: &mut R, options: &ReadOptions, args: Self::Args, @@ -214,7 +214,7 @@ impl BinRead for [B; N] { fn after_parse(&mut self, reader: &mut R, ro: &ReadOptions, args: B::Args) -> BinResult<()> where - R: Read + Seek, + R: Read + Seek + ?Sized, { for val in self.iter_mut() { val.after_parse(reader, ro, args.clone())?; @@ -230,7 +230,7 @@ macro_rules! binread_tuple_impl { impl<$type1: BinRead, $($types: BinRead),*> BinRead for ($type1, $($types),*) { type Args = (); - fn read_options(reader: &mut R, options: &ReadOptions, _: Self::Args) -> BinResult { + fn read_options(reader: &mut R, options: &ReadOptions, _: Self::Args) -> BinResult { Ok(( BinRead::read_options(reader, options, ())?, $( @@ -239,7 +239,7 @@ macro_rules! binread_tuple_impl { )) } - fn after_parse(&mut self, reader: &mut R, options: &ReadOptions, _: Self::Args) -> BinResult<()> { + fn after_parse(&mut self, reader: &mut R, options: &ReadOptions, _: Self::Args) -> BinResult<()> { let ($type1, $( $types ),*) = self; @@ -267,7 +267,11 @@ binread_tuple_impl!( impl BinRead for () { type Args = (); - fn read_options(_: &mut R, _: &ReadOptions, _: Self::Args) -> BinResult { + fn read_options( + _: &mut R, + _: &ReadOptions, + _: Self::Args, + ) -> BinResult { Ok(()) } } @@ -275,7 +279,7 @@ impl BinRead for () { impl BinRead for Box { type Args = T::Args; - fn read_options( + fn read_options( reader: &mut R, options: &ReadOptions, args: Self::Args, @@ -287,7 +291,7 @@ impl BinRead for Box { impl BinRead for Option { type Args = T::Args; - fn read_options( + fn read_options( reader: &mut R, options: &ReadOptions, args: Self::Args, @@ -302,7 +306,7 @@ impl BinRead for Option { args: Self::Args, ) -> BinResult<()> where - R: Read + Seek, + R: Read + Seek + ?Sized, { match self { Some(val) => val.after_parse(reader, ro, args), @@ -314,7 +318,11 @@ impl BinRead for Option { impl BinRead for core::marker::PhantomData { type Args = (); - fn read_options(_: &mut R, _: &ReadOptions, _: Self::Args) -> BinResult { + fn read_options( + _: &mut R, + _: &ReadOptions, + _: Self::Args, + ) -> BinResult { Ok(core::marker::PhantomData) } } diff --git a/binrw/src/binread/mod.rs b/binrw/src/binread/mod.rs index 6d067da1..cbce3b74 100644 --- a/binrw/src/binread/mod.rs +++ b/binrw/src/binread/mod.rs @@ -52,7 +52,7 @@ pub trait BinRead: Sized + 'static { type Args: Clone; /// Read `Self` from the reader using default arguments. - fn read(reader: &mut R) -> BinResult + fn read(reader: &mut R) -> BinResult where Self::Args: Default, { @@ -66,7 +66,7 @@ pub trait BinRead: Sized + 'static { /// Read `Self` from the reader using the given [`ReadOptions`] and /// arguments. - fn read_options( + fn read_options( reader: &mut R, options: &ReadOptions, args: Self::Args, @@ -74,7 +74,7 @@ pub trait BinRead: Sized + 'static { /// Runs any post-processing steps required to finalize construction of the /// object. - fn after_parse( + fn after_parse( &mut self, _: &mut R, _: &ReadOptions, diff --git a/binrw/src/binwrite/impls.rs b/binrw/src/binwrite/impls.rs index 0cb72757..7b344d1a 100644 --- a/binrw/src/binwrite/impls.rs +++ b/binrw/src/binwrite/impls.rs @@ -18,7 +18,7 @@ macro_rules! binwrite_num_impl { impl BinWrite for $type_name { type Args = (); - fn write_options( + fn write_options( &self, writer: &mut W, options: &WriteOptions, @@ -43,7 +43,7 @@ macro_rules! binwrite_nonzero_num_impl { impl BinWrite for $non_zero_type { type Args = (); - fn write_options( + fn write_options( &self, writer: &mut W, options: &WriteOptions, @@ -82,7 +82,7 @@ binwrite_nonzero_num_impl!( impl BinWrite for [T; N] { type Args = T::Args; - fn write_options( + fn write_options( &self, writer: &mut W, options: &WriteOptions, @@ -103,7 +103,7 @@ impl BinWrite for [T; N] { impl BinWrite for [T] { type Args = T::Args; - fn write_options( + fn write_options( &self, writer: &mut W, options: &WriteOptions, @@ -120,7 +120,7 @@ impl BinWrite for [T] { impl BinWrite for Vec { type Args = T::Args; - fn write_options( + fn write_options( &self, writer: &mut W, options: &WriteOptions, @@ -145,7 +145,7 @@ impl BinWrite for Vec { impl BinWrite for &T { type Args = T::Args; - fn write_options( + fn write_options( &self, writer: &mut W, options: &WriteOptions, @@ -158,7 +158,7 @@ impl BinWrite for &T { impl BinWrite for Box { type Args = T::Args; - fn write_options( + fn write_options( &self, writer: &mut W, options: &WriteOptions, @@ -177,7 +177,7 @@ impl BinWrite for Box { impl BinWrite for Option { type Args = T::Args; - fn write_options( + fn write_options( &self, writer: &mut W, options: &WriteOptions, @@ -193,7 +193,7 @@ impl BinWrite for Option { impl BinWrite for PhantomData { type Args = T::Args; - fn write_options( + fn write_options( &self, _: &mut W, _: &WriteOptions, @@ -210,7 +210,7 @@ impl BinWrite for PhantomData { impl BinWrite for () { type Args = (); - fn write_options( + fn write_options( &self, _: &mut W, _: &WriteOptions, @@ -228,7 +228,7 @@ macro_rules! binwrite_tuple_impl { > BinWrite for ($type1, $($types),*) { type Args = (); - fn write_options( + fn write_options( &self, writer: &mut W, options: &WriteOptions, diff --git a/binrw/src/binwrite/mod.rs b/binrw/src/binwrite/mod.rs index 0009f28e..e651f339 100644 --- a/binrw/src/binwrite/mod.rs +++ b/binrw/src/binwrite/mod.rs @@ -14,7 +14,7 @@ pub trait BinWrite { type Args: Clone; /// Write a type to a writer while assuming no arguments are needed. - fn write_to(&self, writer: &mut W) -> BinResult<()> + fn write_to(&self, writer: &mut W) -> BinResult<()> where Self::Args: Default, { @@ -22,13 +22,17 @@ pub trait BinWrite { } /// Write the type to a writer while providing the default [`WriteOptions`] - fn write_with_args(&self, writer: &mut W, args: Self::Args) -> BinResult<()> { + fn write_with_args( + &self, + writer: &mut W, + args: Self::Args, + ) -> BinResult<()> { self.write_options(writer, &WriteOptions::default(), args) } /// Write the type to a writer, given the options on how to write it and the type-specific /// arguments - fn write_options( + fn write_options( &self, writer: &mut W, options: &WriteOptions, diff --git a/binrw/src/file_ptr.rs b/binrw/src/file_ptr.rs index 4614a6f0..0bd5a9dd 100644 --- a/binrw/src/file_ptr.rs +++ b/binrw/src/file_ptr.rs @@ -84,7 +84,7 @@ impl + IntoSeekFrom, BR: BinRead> BinRead for FilePtr( + fn read_options( reader: &mut R, options: &ReadOptions, _: Self::Args, @@ -98,7 +98,7 @@ impl + IntoSeekFrom, BR: BinRead> BinRead for FilePtr(&mut self, reader: &mut R, ro: &ReadOptions, args: BR::Args) -> BinResult<()> where - R: Read + Seek, + R: Read + Seek + ?Sized, { self.after_parse_with_parser(BR::read_options, BR::after_parse, reader, ro, args) } @@ -113,7 +113,7 @@ impl + IntoSeekFrom, T> FilePtr { args: Args, ) -> BinResult where - R: Read + Seek, + R: Read + Seek + ?Sized, Args: Clone, Parser: Fn(&mut R, &ReadOptions, Args) -> BinResult, AfterParse: Fn(&mut T, &mut R, &ReadOptions, Args) -> BinResult<()>, @@ -135,7 +135,7 @@ impl + IntoSeekFrom, T> FilePtr { args: Args, ) -> BinResult<()> where - R: Read + Seek, + R: Read + Seek + ?Sized, Args: Clone, Parser: Fn(&mut R, &ReadOptions, Args) -> BinResult, AfterParse: Fn(&mut T, &mut R, &ReadOptions, Args) -> BinResult<()>, @@ -160,7 +160,7 @@ impl + IntoSeekFrom, T> FilePtr { /// value as the result. pub fn parse(reader: &mut R, options: &ReadOptions, args: Args) -> BinResult where - R: Read + Seek, + R: Read + Seek + ?Sized, Args: Clone, T: BinRead, { @@ -176,7 +176,7 @@ impl + IntoSeekFrom, T> FilePtr { /// value as the result. pub fn parse_with(parser: F) -> impl Fn(&mut R, &ReadOptions, Args) -> BinResult where - R: Read + Seek, + R: Read + Seek + ?Sized, Args: Clone, F: Fn(&mut R, &ReadOptions, Args) -> BinResult, { @@ -192,7 +192,7 @@ impl + IntoSeekFrom, T> FilePtr { /// as the result. pub fn with(parser: F) -> impl Fn(&mut R, &ReadOptions, Args) -> BinResult where - R: Read + Seek, + R: Read + Seek + ?Sized, Args: Clone, F: Fn(&mut R, &ReadOptions, Args) -> BinResult, { diff --git a/binrw/src/helpers.rs b/binrw/src/helpers.rs index d204758d..0616803c 100644 --- a/binrw/src/helpers.rs +++ b/binrw/src/helpers.rs @@ -30,7 +30,7 @@ pub fn until( ) -> impl Fn(&mut Reader, &ReadOptions, Arg) -> BinResult where T: BinRead, - Reader: Read + Seek, + Reader: Read + Seek + ?Sized, CondFn: Fn(&T) -> bool, Arg: Clone, Ret: core::iter::FromIterator, @@ -66,7 +66,7 @@ pub fn until_with( read: ReadFn, ) -> impl Fn(&mut Reader, &ReadOptions, Arg) -> BinResult where - Reader: Read + Seek, + Reader: Read + Seek + ?Sized, CondFn: Fn(&T) -> bool, Arg: Clone, ReadFn: Fn(&mut Reader, &ReadOptions, Arg) -> BinResult, @@ -110,7 +110,7 @@ pub fn until_exclusive( ) -> impl Fn(&mut Reader, &ReadOptions, Arg) -> BinResult where T: BinRead, - Reader: Read + Seek, + Reader: Read + Seek + ?Sized, CondFn: Fn(&T) -> bool, Arg: Clone, Ret: core::iter::FromIterator, @@ -146,7 +146,7 @@ pub fn until_exclusive_with( read: ReadFn, ) -> impl Fn(&mut Reader, &ReadOptions, Arg) -> BinResult where - Reader: Read + Seek, + Reader: Read + Seek + ?Sized, CondFn: Fn(&T) -> bool, Arg: Clone, ReadFn: Fn(&mut Reader, &ReadOptions, Arg) -> BinResult, @@ -191,7 +191,7 @@ pub fn until_eof( ) -> BinResult where T: BinRead, - Reader: Read + Seek, + Reader: Read + Seek + ?Sized, Arg: Clone, Ret: core::iter::FromIterator, { @@ -225,7 +225,7 @@ pub fn until_eof_with( read: ReadFn, ) -> impl Fn(&mut Reader, &ReadOptions, Arg) -> BinResult where - Reader: Read + Seek, + Reader: Read + Seek + ?Sized, Arg: Clone, ReadFn: Fn(&mut Reader, &ReadOptions, Arg) -> BinResult, Ret: core::iter::FromIterator, @@ -277,7 +277,7 @@ fn not_enough_bytes(_: T) -> Error { pub fn count(n: usize) -> impl Fn(&mut R, &ReadOptions, Arg) -> BinResult where T: BinRead, - R: Read + Seek, + R: Read + Seek + ?Sized, Arg: Clone, Ret: core::iter::FromIterator + 'static, { @@ -326,7 +326,7 @@ pub fn count_with( read: ReadFn, ) -> impl Fn(&mut R, &ReadOptions, Arg) -> BinResult where - R: Read + Seek, + R: Read + Seek + ?Sized, Arg: Clone, ReadFn: Fn(&mut R, &ReadOptions, Arg) -> BinResult, Ret: core::iter::FromIterator + 'static, diff --git a/binrw/src/pos_value.rs b/binrw/src/pos_value.rs index 5780f0fc..023acd57 100644 --- a/binrw/src/pos_value.rs +++ b/binrw/src/pos_value.rs @@ -32,7 +32,7 @@ pub struct PosValue { impl BinRead for PosValue { type Args = T::Args; - fn read_options( + fn read_options( reader: &mut R, options: &ReadOptions, args: T::Args, @@ -45,7 +45,7 @@ impl BinRead for PosValue { }) } - fn after_parse( + fn after_parse( &mut self, reader: &mut R, options: &ReadOptions, diff --git a/binrw/src/private.rs b/binrw/src/private.rs index 6b899fa7..974da416 100644 --- a/binrw/src/private.rs +++ b/binrw/src/private.rs @@ -55,7 +55,7 @@ where pub fn magic(reader: &mut R, expected: B, options: &ReadOptions) -> BinResult<()> where B: BinRead + core::fmt::Debug + PartialEq + Sync + Send + 'static, - R: io::Read + io::Seek, + R: io::Read + io::Seek + ?Sized, { let pos = reader.stream_position()?; let val = B::read_options(reader, options, ())?; @@ -71,7 +71,7 @@ where pub fn parse_function_args_type_hint(_: F, a: Args) -> Args where - R: crate::io::Read + Seek, + R: crate::io::Read + Seek + ?Sized, F: FnOnce(&mut R, &crate::ReadOptions, Args) -> crate::BinResult, { a @@ -79,7 +79,7 @@ where pub fn write_function_args_type_hint(_: F, a: Args) -> Args where - W: Write + Seek, + W: Write + Seek + ?Sized, F: FnOnce(&T, &mut W, &crate::WriteOptions, Args) -> crate::BinResult<()>, { a @@ -96,7 +96,7 @@ where pub fn write_fn_type_hint(x: WriterFn) -> WriterFn where Args: Clone, - Writer: Write + Seek, + Writer: Write + Seek + ?Sized, WriterFn: Fn(&T, &mut Writer, &WriteOptions, Args) -> BinResult<()>, { x @@ -136,7 +136,7 @@ pub fn write_fn_map_output_type_hint Output, Args: Clone, - Writer: Write + Seek, + Writer: Write + Seek + ?Sized, WriteFn: Fn(&Output, &mut Writer, &WriteOptions, Args) -> BinResult<()>, { func @@ -150,13 +150,13 @@ where Error: CustomError, MapFn: FnOnce(Input) -> Result, Args: Clone, - Writer: Write + Seek, + Writer: Write + Seek + ?Sized, WriteFn: Fn(&Output, &mut Writer, &WriteOptions, Args) -> BinResult<()>, { func } -pub fn write_zeroes(writer: &mut W, count: u64) -> BinResult<()> { +pub fn write_zeroes(writer: &mut W, count: u64) -> BinResult<()> { const BUF_SIZE: u64 = 0x20; const ZEROES: [u8; BUF_SIZE as usize] = [0u8; BUF_SIZE as usize]; diff --git a/binrw/src/punctuated.rs b/binrw/src/punctuated.rs index 019b2085..32cc7231 100644 --- a/binrw/src/punctuated.rs +++ b/binrw/src/punctuated.rs @@ -69,7 +69,7 @@ impl> Punctuated { /// # assert_eq!(*y.x, vec![3, 2, 1]); /// # assert_eq!(y.x.separators, vec![0, 1]); /// ``` - pub fn separated( + pub fn separated( reader: &mut R, options: &ReadOptions, args: VecArgs, @@ -91,7 +91,7 @@ impl> Punctuated { /// a trailing `P`. /// /// Requires a count to be passed via `#[br(count)]`. - pub fn separated_trailing( + pub fn separated_trailing( reader: &mut R, options: &ReadOptions, args: VecArgs, diff --git a/binrw/src/strings.rs b/binrw/src/strings.rs index 710b5da6..3c5b19dc 100644 --- a/binrw/src/strings.rs +++ b/binrw/src/strings.rs @@ -39,7 +39,7 @@ pub struct NullString( impl BinRead for NullString { type Args = (); - fn read_options( + fn read_options( reader: &mut R, options: &ReadOptions, _: Self::Args, @@ -59,7 +59,7 @@ impl BinRead for NullString { impl BinWrite for NullString { type Args = (); - fn write_options( + fn write_options( &self, writer: &mut W, options: &crate::WriteOptions, @@ -161,7 +161,7 @@ pub struct NullWideString( impl BinRead for NullWideString { type Args = (); - fn read_options( + fn read_options( reader: &mut R, options: &ReadOptions, _: Self::Args, @@ -181,7 +181,7 @@ impl BinRead for NullWideString { impl BinWrite for NullWideString { type Args = (); - fn write_options( + fn write_options( &self, writer: &mut W, options: &crate::WriteOptions, diff --git a/binrw/tests/derive/struct.rs b/binrw/tests/derive/struct.rs index 0b1e9284..76e617d1 100644 --- a/binrw/tests/derive/struct.rs +++ b/binrw/tests/derive/struct.rs @@ -25,7 +25,7 @@ fn all_the_things() { calc_test: u32, } - fn read_offsets( + fn read_offsets( reader: &mut R, ro: &ReadOptions, _: (), diff --git a/binrw/tests/derive/write/custom_writer.rs b/binrw/tests/derive/write/custom_writer.rs index 75c8fcbe..22469f1f 100644 --- a/binrw/tests/derive/write/custom_writer.rs +++ b/binrw/tests/derive/write/custom_writer.rs @@ -10,7 +10,7 @@ fn custom_writer() { y: u16, } - fn custom_writer( + fn custom_writer( _this: &u16, writer: &mut W, _opts: &WriteOptions, diff --git a/binrw_derive/src/codegen/mod.rs b/binrw_derive/src/codegen/mod.rs index 6ee4fea5..d3afc7d4 100644 --- a/binrw_derive/src/codegen/mod.rs +++ b/binrw_derive/src/codegen/mod.rs @@ -46,7 +46,7 @@ pub(crate) fn generate_binread_impl( impl #impl_generics #BINREAD_TRAIT for #name #ty_generics #where_clause { type Args = #arg_type; - fn read_options + fn read_options (#READER: &mut R, #OPT: &#READ_OPTIONS, #ARGS: Self::Args) -> #BIN_RESULT { @@ -87,7 +87,7 @@ pub(crate) fn generate_binwrite_impl( impl #impl_generics #BINWRITE_TRAIT for #name #ty_generics #where_clause { type Args = #arg_type; - fn write_options( + fn write_options( &self, #WRITER: &mut W, #OPT: &#WRITE_OPTIONS,