use ;
use ;
/// An extension trait to `std::io::Read` streams; this only deserializes simple types, like `u8`, `i32`, `f32`, `usize`, etc.
///
/// If you implement [`FromCtx`](trait.FromCtx.html) and [`SizeWith`](ctx/trait.SizeWith.html) for your type, you can then `ioread::<YourType>()` on a `Read`. Note: [`FromCtx`](trait.FromCtx.html) is only meant for very simple types, and should _never_ fail.
///
/// **NB** You should probably add `repr(packed)` or `repr(C)` and be very careful how you implement [`SizeWith`](ctx/trait.SizeWith.html), otherwise you
/// will get IO errors failing to fill entire buffer (the size you specified in `SizeWith`), or out of bound errors (depending on your impl) in `from_ctx`
///
/// # Example
/// ```rust
/// use std::io::Cursor;
/// use scroll::{self, ctx, Pread, IOread};
///
/// #[repr(packed)]
/// struct Foo {
/// foo: usize,
/// bar: u32,
/// }
///
/// impl ctx::FromCtx<scroll::Endian> for Foo {
/// fn from_ctx(bytes: &[u8], ctx: scroll::Endian) -> Self {
/// Foo { foo: bytes.pread_with::<usize>(0, ctx).unwrap(), bar: bytes.pread_with::<u32>(8, ctx).unwrap() }
/// }
/// }
///
/// impl ctx::SizeWith<scroll::Endian> for Foo {
/// type Units = usize;
/// // our parsing context doesn't influence our size
/// fn size_with(_: &scroll::Endian) -> Self::Units {
/// ::std::mem::size_of::<Foo>()
/// }
/// }
///
/// let bytes_ = [0x0b,0x0b,0x00,0x00,0x00,0x00,0x00,0x00, 0xef,0xbe,0x00,0x00,];
/// let mut bytes = Cursor::new(bytes_);
/// let foo = bytes.ioread::<usize>().unwrap();
/// let bar = bytes.ioread::<u32>().unwrap();
/// assert_eq!(foo, 0xb0b);
/// assert_eq!(bar, 0xbeef);
/// let error = bytes.ioread::<f64>();
/// assert!(error.is_err());
/// let mut bytes = Cursor::new(bytes_);
/// let foo_ = bytes.ioread::<Foo>().unwrap();
/// assert_eq!(foo_.foo, foo);
/// assert_eq!(foo_.bar, bar);
/// ```
///
/// Types that implement `Read` get methods defined in `IOread`
/// for free.
/// An extension trait to `std::io::Write` streams; this only serializes simple types, like `u8`, `i32`, `f32`, `usize`, etc.
///
/// To write custom types with a single `iowrite::<YourType>` call, implement [`IntoCtx`](trait.IntoCtx.html) and [`SizeWith`](ctx/trait.SizeWith.html) for `YourType`.
/// Types that implement `Write` get methods defined in `IOwrite`
/// for free.