flexible_io/
lib.rs

1//! Flexible IO allows you to choose seekable or buffered IO at runtime.
2//!
3//! The motivation of this is enabling APIs in which use of a reader (or writer) can be optimized
4//! in case of it being buffered, but it's not required for correct functioning. Or, an API where
5//! the Seek requirement is only determined at runtime, such as when a portion of the functionality
6//! does not depend on it, and an error should be returned.
7//!
8//! Note that the wrapped type can not be unsized (`dyn` trait) itself. This may be fixed at a
9//! later point to make the reader suitable for use in embedded. In particular, the double
10//! indirection of instantiating with `R = &mut dyn Read` wouldn't make sense as the setters would
11//! not be usable, their bounds can never be met. And combining traits into a large dyn-trait is
12//! redundant as it trait-impls become part of the static validity requirement again.
13#![cfg_attr(feature = "unstable_set_ptr_value", feature(set_ptr_value))]
14#[deny(missing_docs)]
15
16macro_rules! lifetime_erase_trait_vtable {
17    ((&mut $r:expr): $lt:lifetime as $trait:path) => {{
18        // Safety: Transmuting pointer-to-pointer, and they only differ by lifetime. Types must not
19        // be specialized on lifetime parameters.
20        let vtable = (&mut $r) as &mut (dyn $trait + $lt) as *mut (dyn $trait + $lt);
21        unsafe { core::mem::transmute::<_, *mut (dyn $trait + 'static)>(vtable) }
22    }};
23}
24
25/// Provides wrappers for values of [`Read`](std::io::Read) types.
26pub mod reader;
27/// Provides wrappers for values of [`Write`](std::io::Write) types.
28pub mod writer;
29
30mod stable_with_metadata_of;
31
32pub use reader::Reader;
33pub use writer::Writer;