Skip to content

Commit 5c8c911

Browse files
ScanMountGoatcsnover
authored andcommitted
Reduce generic copies of restore_position
Refs jam1garner#319.
1 parent 999da45 commit 5c8c911

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

binrw/src/binread/impls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ macro_rules! binread_impl {
1919
let mut val = [0; core::mem::size_of::<$type_name>()];
2020
let pos = reader.stream_position()?;
2121

22-
reader.read_exact(&mut val).or_else(crate::__private::restore_position(reader, pos))?;
22+
reader.read_exact(&mut val).map_err(crate::__private::restore_position(reader, pos))?;
2323
Ok(match endian {
2424
Endian::Big => {
2525
<$type_name>::from_be_bytes(val)

binrw/src/private.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,13 @@ where
167167
args
168168
}
169169

170-
pub fn restore_position<E: Into<Error>, S: Seek, T>(
170+
pub fn restore_position<E: Into<Error>, S: Seek>(
171171
stream: &mut S,
172172
pos: u64,
173-
) -> impl FnOnce(E) -> BinResult<T> + '_ {
173+
) -> impl FnOnce(E) -> Error + '_ {
174174
move |error| match stream.seek(SeekFrom::Start(pos)) {
175-
Ok(_) => Err(error.into()),
176-
Err(seek_error) => Err(restore_position_err(error.into(), seek_error.into())),
175+
Ok(_) => error.into(),
176+
Err(seek_error) => restore_position_err(error.into(), seek_error.into()),
177177
}
178178
}
179179

binrw_derive/src/binrw/codegen/read_options.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub(crate) fn generate(input: &Input, derive_input: &syn::DeriveInput) -> TokenS
5353

5454
let rewind = (needs_rewind || input.magic().is_some()).then(|| {
5555
quote! {
56-
.or_else(#RESTORE_POSITION::<binrw::Error, _, _>(#reader_var, #POS))
56+
.map_err(#RESTORE_POSITION::<binrw::Error, _>(#reader_var, #POS))
5757
}
5858
});
5959

0 commit comments

Comments
 (0)