binread/io/
mod.rs

1//! A swappable version of [std::io](std::io) that works in `no_std + alloc` environments.
2//! If the feature flag `std` is enabled (as it is by default), this will just re-export types from `std::io`.
3
4pub mod error;
5pub mod prelude;
6
7#[cfg(any(not(feature = "std"), test))]
8pub mod cursor;
9
10#[cfg(any(not(feature = "std"), test))]
11mod no_std;
12
13#[cfg(not(feature = "std"))]
14pub use no_std::*;
15
16#[cfg(feature = "std")]
17pub use std::io::{Bytes, Cursor, Error, ErrorKind, Read, Result, Seek, SeekFrom};
18
19pub trait StreamPosition {
20    fn stream_pos(&mut self) -> Result<u64>;
21}
22
23impl<T: Seek> StreamPosition for T {
24    #[rustversion::before(1.51)]
25    #[cfg(feature = "std")]
26    fn stream_pos(&mut self) -> Result<u64> {
27        self.seek(SeekFrom::Current(0))
28    }
29
30    // would prefer any(since(1.51), not(feature = "std"))
31    // but i don't know how to compose rustversion and cfg like that
32    #[rustversion::since(1.51)]
33    #[cfg(feature = "std")]
34    fn stream_pos(&mut self) -> Result<u64> {
35        self.stream_position()
36    }
37
38    #[cfg(not(feature = "std"))]
39    fn stream_pos(&mut self) -> Result<u64> {
40        self.stream_position()
41    }
42}