Trait scroll::Gread [] [src]

pub trait Gread<Ctx = Endian, E = Error, I = usize, TryCtx = (I, Ctx), SliceCtx = (I, I, Ctx)>: Pread<Ctx, E, I> + TryOffset<E, I> where Ctx: Copy + Default + Debug,
               I: AddAssign + Copy + Add + Default + Debug,
               E: Debug,
               TryCtx: Copy + Debug,
               SliceCtx: Copy + Default + Debug
{ fn gread_unsafe<'a, N: TryFromCtx<'a, (I, Ctx), Error=E>>(&'a self,
                                                              offset: &mut I,
                                                              ctx: Ctx)
                                                              -> N { ... } fn gread<'a, N: TryFromCtx<'a, (I, Ctx), Error=E>>(&'a self,
                                                       offset: &mut I)
                                                       -> Result<N, E> { ... } fn gread_with<'a, N: TryFromCtx<'a, (I, Ctx), Error=E>>(&'a self,
                                                            offset: &mut I,
                                                            ctx: Ctx)
                                                            -> Result<N, E> { ... } fn gread_slice<N: ?Sized>(&self, offset: &mut I, count: I) -> Result<&N, E> where N: TryRefFromCtx<(I, I, Ctx), Error=E> { ... } fn gread_inout<'a, N>(&'a self,
                          offset: &mut I,
                          inout: &mut [N])
                          -> Result<(), E> where N: TryFromCtx<'a, (I, Ctx), Error=E> { ... } fn gread_inout_with<'a, N>(&'a self,
                               offset: &mut I,
                               inout: &mut [N],
                               ctx: Ctx)
                               -> Result<(), E> where N: TryFromCtx<'a, (I, Ctx), Error=E> { ... } }

The Greater Read (Gread) reads a value at a mutable offset, and increments the offset by the size of the interpreted value.

Gread implements an immutable Self, mutable reference offset incrementor which uses Pread as its base. If you are writing a custom Gread interface, you should only need to implement Pread for a particular Ctx, Error, Index target, and implement TryOffset to explain to the trait how it should increment the mutable offset, and then a simple blanket impl Gread<I, E, Ctx> for YourType, etc.

Provided Methods

Reads a value from self at offset with a default Ctx. For the primitive numeric values, this will read at the machine's endianness. Updates the offset

Example

use scroll::Gread;
let offset = &mut 0;
let bytes = [0x7fu8; 0x01];
let byte = bytes.gread::<u8>(offset).unwrap();
assert_eq!(*offset, 1);

Reads a value from self at offset with the given ctx, and updates the offset.

Example

use scroll::Gread;
let offset = &mut 0;
let bytes: [u8; 2] = [0xde, 0xad];
let dead: u16 = bytes.gread_with(offset, scroll::BE).unwrap();
assert_eq!(dead, 0xdeadu16);
assert_eq!(*offset, 2);

Slices an N from self at offset up to count times, and updates the offset.

Example

use scroll::Gread;
let bytes: [u8; 2] = [0x48, 0x49];
let offset = &mut 0;
let hi: &str = bytes.gread_slice(offset, 2).unwrap();
assert_eq!(hi, "HI");
assert_eq!(*offset, 2);

Trys to write inout.len() Ns into inout from Self starting at offset, using the default context for N, and updates the offset.

Example

use scroll::Gread;
let mut bytes: Vec<u8> = vec![0, 0];
let offset = &mut 0;
let bytes_from: [u8; 2] = [0x48, 0x49];
bytes_from.gread_inout(offset, &mut bytes).unwrap();
assert_eq!(&bytes, &bytes_from);
assert_eq!(*offset, 2);

Trys to write inout.len() Ns into inout from Self starting at offset, using the context ctx

Example

use scroll::{ctx, Gread};
let mut bytes: Vec<u8> = vec![0, 0];
let offset = &mut 0;
let bytes_from: [u8; 2] = [0x48, 0x49];
bytes_from.gread_inout_with(offset, &mut bytes, ctx::CTX).unwrap();
assert_eq!(&bytes, &bytes_from);
assert_eq!(*offset, 2);

Implementors