[][src]Struct bitcursor::BitCursor

pub struct BitCursor<T> { /* fields omitted */ }

A 'BitCursor' wraps an in memory buffer and provides it with a Seek implementation provided that memory buffer impls the Unit trait

'BitCursors' are used in memory buffers, any slice with types implementing Unit, to allow it to read/write sizes of whatever unit implementation you pass in, starting from the current bit position

It has implementations for some standard library traits such as ['Seek'] ['Read'] ['BufRead']

Examples

use std::io::{Read, Seek, SeekFrom};
use BitCursor;
fn read_from_bits() {
    let data = [
        false, true, true, false, true, false, true, false, true, true, true, true, false,
        false, false, true, false, true, true, true, false, true, false, false,
    ];
    let mut bcurs = BitCursor::new(&data[..]);
    let _ = bcurs.seek(SeekFrom::Start(13));
    let mut buf = vec![0, 0, 0, 0];
    let amt = bcurs.read(&mut buf).unwrap();
    assert_eq!(2, amt);
    assert_eq!(vec![46, 128, 0, 0], Vec::from(buf))
}

Methods

impl<T> BitCursor<T>[src]

Important traits for BitCursor<&'a mut [T]>
pub fn new(data: T) -> BitCursor<T>[src]

Creates a new BitCursor wrapping the provided underlying in-memory buffer.

Initial position for the bitcursor's unit cursor is 0, similarly the bit position will start at 0 Similarly to std::io::Cursor writing to the Bitcursor starts with overwriting vector content, not appending it!

Examples

use BitCursor;

let buff = BitCursor::new(Vec::new());

pub fn into_inner(self) -> T[src]

Consumes the BitCursor, returning the underlying value.

Examples

use BitCursor;

let buff = BitCursor::new(Vec::new());

let inner = buff.into_inner();

pub fn get_ref(&self) -> &T[src]

Get a reference to the underlying value in this BitCursor

Examples

use BitCursor;

let buff = BitCursor::new(Vec::new());

let reference = buff.get_ref();

pub fn get_mut(&mut self) -> &mut T[src]

Gets a mutable reference to the underlying value in this BitCursor.

Care should be taken to avoid modifying the internal I/O state of the underlying value as it may corrupt this cursor's position.

Examples

use BitCursor;

let mut buff = BitCursor::new(Vec::new());

let reference = buff.get_mut();

pub fn cur_position(&self) -> u64[src]

Returns the current position of this BitCursor.

Examples

use BitCursor;
use std::io::prelude::*;
use std::io::SeekFrom;

let mut buff: BitCursor<Vec<u8>> = BitCursor::new(vec![1, 2, 3, 4, 5]);

assert_eq!(buff.cur_position(), 0);

buff.seek(SeekFrom::Current(16)).unwrap();
assert_eq!(buff.cur_position(), 2);

buff.seek(SeekFrom::Current(-1)).unwrap();
assert_eq!(buff.cur_position(), 1);

pub fn bit_position(&self) -> u8[src]

Returns the current bit position of this BitCursor.

Examples

use BitCursor;
use std::io::prelude::*;
use std::io::SeekFrom;

let mut buff: BitCursor<Vec<u8>> = BitCursor::new(vec![1, 2, 3, 4, 5]);

assert_eq!(buff.bit_position(), 0);

buff.seek(SeekFrom::Current(16)).unwrap();
assert_eq!(buff.bit_position(), 0);

buff.seek(SeekFrom::Current(-1)).unwrap();
assert_eq!(buff.bit_position(), 7);

pub fn set_bit_pos(&mut self, new: u8)[src]

Sets the bit position of this BitCursor. does not wrap to the size of the Unit type also allows going over the length of the BitCursor it's recommended to use std::io::Seek

Examples

use BitCursor;

let mut buff: BitCursor<Vec<u8>> = BitCursor::new(vec![1, 2, 3, 4, 5]);

assert_eq!(buff.position(), 0);

buff.set_bit_pos(2);
assert_eq!(buff.bit_position(), 2);

buff.set_bit_pos(4);
assert_eq!(buff.bit_position(), 4);

pub fn set_cur_pos(&mut self, new: u64)[src]

Sets the position of this BitCursor. also allows going over the length of the BitCursor it's recommended to use std::io::Seek

Examples

use BitCursor;

let mut buff: BitCursor<Vec<u8>> = BitCursor::new(vec![1, 2, 3, 4, 5]);

assert_eq!(buff.cur_position(), 0);

buff.set_cur_pos(2);
assert_eq!(buff.cur_position(), 2);

buff.set_cur_pos(4);
assert_eq!(buff.cur_position(), 4);

Trait Implementations

impl<'a, T: Unit> ReadBits<T> for BitCursor<&'a [T]>[src]

impl<'a, T: Unit> ReadBits<T> for BitCursor<&'a mut [T]>[src]

impl<'a, T: Unit> ReadBits<T> for BitCursor<Vec<T>>[src]

impl<'a, T: Unit> ReadBits<T> for BitCursor<&'a Vec<T>>[src]

impl<'a, T: Unit> ReadBits<T> for BitCursor<&'a mut Vec<T>>[src]

impl<'a, T: Unit> ReadBits<T> for BitCursor<T>[src]

impl<'a, T: Unit> ForceReadBits<T> for BitCursor<&'a [T]>[src]

impl<'a, T: Unit> ForceReadBits<T> for BitCursor<&'a mut [T]>[src]

impl<'a, T: Unit> ForceReadBits<T> for BitCursor<Vec<T>>[src]

impl<'a, T: Unit> ForceReadBits<T> for BitCursor<&'a Vec<T>>[src]

impl<'a, T: Unit> ForceReadBits<T> for BitCursor<&'a mut Vec<T>>[src]

impl<'a, T: Unit> ForceReadBits<T> for BitCursor<T>[src]

impl<T: Clone> Clone for BitCursor<T>[src]

default fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl<T: Debug> Debug for BitCursor<T>[src]

impl<'a> BufRead for BitCursor<&'a [u8]>[src]

default fn read_until(
    &mut self,
    byte: u8,
    buf: &mut Vec<u8>
) -> Result<usize, Error>
1.0.0
[src]

Read all bytes into buf until the delimiter byte or EOF is reached. Read more

default fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
1.0.0
[src]

Read all bytes until a newline (the 0xA byte) is reached, and append them to the provided buffer. Read more

default fn split(self, byte: u8) -> Split<Self>
1.0.0
[src]

Returns an iterator over the contents of this reader split on the byte byte. Read more

default fn lines(self) -> Lines<Self>
1.0.0
[src]

Returns an iterator over the lines of this reader. Read more

impl<'a> BufRead for BitCursor<&'a mut [u8]>[src]

default fn read_until(
    &mut self,
    byte: u8,
    buf: &mut Vec<u8>
) -> Result<usize, Error>
1.0.0
[src]

Read all bytes into buf until the delimiter byte or EOF is reached. Read more

default fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
1.0.0
[src]

Read all bytes until a newline (the 0xA byte) is reached, and append them to the provided buffer. Read more

default fn split(self, byte: u8) -> Split<Self>
1.0.0
[src]

Returns an iterator over the contents of this reader split on the byte byte. Read more

default fn lines(self) -> Lines<Self>
1.0.0
[src]

Returns an iterator over the lines of this reader. Read more

impl<'a> BufRead for BitCursor<Vec<u8>>[src]

default fn read_until(
    &mut self,
    byte: u8,
    buf: &mut Vec<u8>
) -> Result<usize, Error>
1.0.0
[src]

Read all bytes into buf until the delimiter byte or EOF is reached. Read more

default fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
1.0.0
[src]

Read all bytes until a newline (the 0xA byte) is reached, and append them to the provided buffer. Read more

default fn split(self, byte: u8) -> Split<Self>
1.0.0
[src]

Returns an iterator over the contents of this reader split on the byte byte. Read more

default fn lines(self) -> Lines<Self>
1.0.0
[src]

Returns an iterator over the lines of this reader. Read more

impl<'a> BufRead for BitCursor<&'a Vec<u8>>[src]

default fn read_until(
    &mut self,
    byte: u8,
    buf: &mut Vec<u8>
) -> Result<usize, Error>
1.0.0
[src]

Read all bytes into buf until the delimiter byte or EOF is reached. Read more

default fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
1.0.0
[src]

Read all bytes until a newline (the 0xA byte) is reached, and append them to the provided buffer. Read more

default fn split(self, byte: u8) -> Split<Self>
1.0.0
[src]

Returns an iterator over the contents of this reader split on the byte byte. Read more

default fn lines(self) -> Lines<Self>
1.0.0
[src]

Returns an iterator over the lines of this reader. Read more

impl<'a> BufRead for BitCursor<&'a mut Vec<u8>>[src]

default fn read_until(
    &mut self,
    byte: u8,
    buf: &mut Vec<u8>
) -> Result<usize, Error>
1.0.0
[src]

Read all bytes into buf until the delimiter byte or EOF is reached. Read more

default fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
1.0.0
[src]

Read all bytes until a newline (the 0xA byte) is reached, and append them to the provided buffer. Read more

default fn split(self, byte: u8) -> Split<Self>
1.0.0
[src]

Returns an iterator over the contents of this reader split on the byte byte. Read more

default fn lines(self) -> Lines<Self>
1.0.0
[src]

Returns an iterator over the lines of this reader. Read more

impl<'a, T: Unit> Write for BitCursor<&'a mut [T]>[src]

default fn write_vectored(&mut self, bufs: &[IoVec]) -> Result<usize, Error>[src]

🔬 This is a nightly-only experimental API. (iovec)

Like write, except that it writes from a slice of buffers. Read more

default fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
1.0.0
[src]

Attempts to write an entire buffer into this writer. Read more

default fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>
1.0.0
[src]

Writes a formatted string into this writer, returning any error encountered. Read more

default fn by_ref(&mut self) -> &mut Self
1.0.0
[src]

Creates a "by reference" adaptor for this instance of Write. Read more

impl<'a, T: Unit> Seek for BitCursor<&'a [T]>[src]

default fn stream_len(&mut self) -> Result<u64, Error>[src]

🔬 This is a nightly-only experimental API. (seek_convenience)

Returns the length of this stream (in bytes). Read more

default fn stream_position(&mut self) -> Result<u64, Error>[src]

🔬 This is a nightly-only experimental API. (seek_convenience)

Returns the current seek position from the start of the stream. Read more

impl<'a, T: Unit> Seek for BitCursor<&'a mut [T]>[src]

default fn stream_len(&mut self) -> Result<u64, Error>[src]

🔬 This is a nightly-only experimental API. (seek_convenience)

Returns the length of this stream (in bytes). Read more

default fn stream_position(&mut self) -> Result<u64, Error>[src]

🔬 This is a nightly-only experimental API. (seek_convenience)

Returns the current seek position from the start of the stream. Read more

impl<'a, T: Unit> Seek for BitCursor<Vec<T>>[src]

default fn stream_len(&mut self) -> Result<u64, Error>[src]

🔬 This is a nightly-only experimental API. (seek_convenience)

Returns the length of this stream (in bytes). Read more

default fn stream_position(&mut self) -> Result<u64, Error>[src]

🔬 This is a nightly-only experimental API. (seek_convenience)

Returns the current seek position from the start of the stream. Read more

impl<'a, T: Unit> Seek for BitCursor<&'a Vec<T>>[src]

default fn stream_len(&mut self) -> Result<u64, Error>[src]

🔬 This is a nightly-only experimental API. (seek_convenience)

Returns the length of this stream (in bytes). Read more

default fn stream_position(&mut self) -> Result<u64, Error>[src]

🔬 This is a nightly-only experimental API. (seek_convenience)

Returns the current seek position from the start of the stream. Read more

impl<'a, T: Unit> Seek for BitCursor<&'a mut Vec<T>>[src]

default fn stream_len(&mut self) -> Result<u64, Error>[src]

🔬 This is a nightly-only experimental API. (seek_convenience)

Returns the length of this stream (in bytes). Read more

default fn stream_position(&mut self) -> Result<u64, Error>[src]

🔬 This is a nightly-only experimental API. (seek_convenience)

Returns the current seek position from the start of the stream. Read more

impl<'a, T: Unit> Seek for BitCursor<T>[src]

default fn stream_len(&mut self) -> Result<u64, Error>[src]

🔬 This is a nightly-only experimental API. (seek_convenience)

Returns the length of this stream (in bytes). Read more

default fn stream_position(&mut self) -> Result<u64, Error>[src]

🔬 This is a nightly-only experimental API. (seek_convenience)

Returns the current seek position from the start of the stream. Read more

impl<'a, T: Unit> Read for BitCursor<&'a [T]>[src]

default fn read_vectored(
    &mut self,
    bufs: &mut [IoVecMut]
) -> Result<usize, Error>
[src]

🔬 This is a nightly-only experimental API. (iovec)

Like read, except that it reads into a slice of buffers. Read more

unsafe default fn initializer(&self) -> Initializer[src]

🔬 This is a nightly-only experimental API. (read_initializer)

Determines if this Reader can work with buffers of uninitialized memory. Read more

default fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
1.0.0
[src]

Read all bytes until EOF in this source, placing them into buf. Read more

default fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
1.0.0
[src]

Read all bytes until EOF in this source, appending them to buf. Read more

default fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
1.6.0
[src]

Read the exact number of bytes required to fill buf. Read more

default fn by_ref(&mut self) -> &mut Self
1.0.0
[src]

Creates a "by reference" adaptor for this instance of Read. Read more

default fn bytes(self) -> Bytes<Self>
1.0.0
[src]

Transforms this Read instance to an [Iterator] over its bytes. Read more

default fn chain<R>(self, next: R) -> Chain<Self, R> where
    R: Read
1.0.0
[src]

Creates an adaptor which will chain this stream with another. Read more

default fn take(self, limit: u64) -> Take<Self>
1.0.0
[src]

Creates an adaptor which will read at most limit bytes from it. Read more

impl<'a, T: Unit> Read for BitCursor<&'a mut [T]>[src]

default fn read_vectored(
    &mut self,
    bufs: &mut [IoVecMut]
) -> Result<usize, Error>
[src]

🔬 This is a nightly-only experimental API. (iovec)

Like read, except that it reads into a slice of buffers. Read more

unsafe default fn initializer(&self) -> Initializer[src]

🔬 This is a nightly-only experimental API. (read_initializer)

Determines if this Reader can work with buffers of uninitialized memory. Read more

default fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
1.0.0
[src]

Read all bytes until EOF in this source, placing them into buf. Read more

default fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
1.0.0
[src]

Read all bytes until EOF in this source, appending them to buf. Read more

default fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
1.6.0
[src]

Read the exact number of bytes required to fill buf. Read more

default fn by_ref(&mut self) -> &mut Self
1.0.0
[src]

Creates a "by reference" adaptor for this instance of Read. Read more

default fn bytes(self) -> Bytes<Self>
1.0.0
[src]

Transforms this Read instance to an [Iterator] over its bytes. Read more

default fn chain<R>(self, next: R) -> Chain<Self, R> where
    R: Read
1.0.0
[src]

Creates an adaptor which will chain this stream with another. Read more

default fn take(self, limit: u64) -> Take<Self>
1.0.0
[src]

Creates an adaptor which will read at most limit bytes from it. Read more

impl<'a, T: Unit> Read for BitCursor<Vec<T>>[src]

default fn read_vectored(
    &mut self,
    bufs: &mut [IoVecMut]
) -> Result<usize, Error>
[src]

🔬 This is a nightly-only experimental API. (iovec)

Like read, except that it reads into a slice of buffers. Read more

unsafe default fn initializer(&self) -> Initializer[src]

🔬 This is a nightly-only experimental API. (read_initializer)

Determines if this Reader can work with buffers of uninitialized memory. Read more

default fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
1.0.0
[src]

Read all bytes until EOF in this source, placing them into buf. Read more

default fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
1.0.0
[src]

Read all bytes until EOF in this source, appending them to buf. Read more

default fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
1.6.0
[src]

Read the exact number of bytes required to fill buf. Read more

default fn by_ref(&mut self) -> &mut Self
1.0.0
[src]

Creates a "by reference" adaptor for this instance of Read. Read more

default fn bytes(self) -> Bytes<Self>
1.0.0
[src]

Transforms this Read instance to an [Iterator] over its bytes. Read more

default fn chain<R>(self, next: R) -> Chain<Self, R> where
    R: Read
1.0.0
[src]

Creates an adaptor which will chain this stream with another. Read more

default fn take(self, limit: u64) -> Take<Self>
1.0.0
[src]

Creates an adaptor which will read at most limit bytes from it. Read more

impl<'a, T: Unit> Read for BitCursor<&'a Vec<T>>[src]

default fn read_vectored(
    &mut self,
    bufs: &mut [IoVecMut]
) -> Result<usize, Error>
[src]

🔬 This is a nightly-only experimental API. (iovec)

Like read, except that it reads into a slice of buffers. Read more

unsafe default fn initializer(&self) -> Initializer[src]

🔬 This is a nightly-only experimental API. (read_initializer)

Determines if this Reader can work with buffers of uninitialized memory. Read more

default fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
1.0.0
[src]

Read all bytes until EOF in this source, placing them into buf. Read more

default fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
1.0.0
[src]

Read all bytes until EOF in this source, appending them to buf. Read more

default fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
1.6.0
[src]

Read the exact number of bytes required to fill buf. Read more

default fn by_ref(&mut self) -> &mut Self
1.0.0
[src]

Creates a "by reference" adaptor for this instance of Read. Read more

default fn bytes(self) -> Bytes<Self>
1.0.0
[src]

Transforms this Read instance to an [Iterator] over its bytes. Read more

default fn chain<R>(self, next: R) -> Chain<Self, R> where
    R: Read
1.0.0
[src]

Creates an adaptor which will chain this stream with another. Read more

default fn take(self, limit: u64) -> Take<Self>
1.0.0
[src]

Creates an adaptor which will read at most limit bytes from it. Read more

impl<'a, T: Unit> Read for BitCursor<&'a mut Vec<T>>[src]

default fn read_vectored(
    &mut self,
    bufs: &mut [IoVecMut]
) -> Result<usize, Error>
[src]

🔬 This is a nightly-only experimental API. (iovec)

Like read, except that it reads into a slice of buffers. Read more

unsafe default fn initializer(&self) -> Initializer[src]

🔬 This is a nightly-only experimental API. (read_initializer)

Determines if this Reader can work with buffers of uninitialized memory. Read more

default fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
1.0.0
[src]

Read all bytes until EOF in this source, placing them into buf. Read more

default fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
1.0.0
[src]

Read all bytes until EOF in this source, appending them to buf. Read more

default fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
1.6.0
[src]

Read the exact number of bytes required to fill buf. Read more

default fn by_ref(&mut self) -> &mut Self
1.0.0
[src]

Creates a "by reference" adaptor for this instance of Read. Read more

default fn bytes(self) -> Bytes<Self>
1.0.0
[src]

Transforms this Read instance to an [Iterator] over its bytes. Read more

default fn chain<R>(self, next: R) -> Chain<Self, R> where
    R: Read
1.0.0
[src]

Creates an adaptor which will chain this stream with another. Read more

default fn take(self, limit: u64) -> Take<Self>
1.0.0
[src]

Creates an adaptor which will read at most limit bytes from it. Read more

impl<'a, T: Unit> Read for BitCursor<T>[src]

default fn read_vectored(
    &mut self,
    bufs: &mut [IoVecMut]
) -> Result<usize, Error>
[src]

🔬 This is a nightly-only experimental API. (iovec)

Like read, except that it reads into a slice of buffers. Read more

unsafe default fn initializer(&self) -> Initializer[src]

🔬 This is a nightly-only experimental API. (read_initializer)

Determines if this Reader can work with buffers of uninitialized memory. Read more

default fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
1.0.0
[src]

Read all bytes until EOF in this source, placing them into buf. Read more

default fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
1.0.0
[src]

Read all bytes until EOF in this source, appending them to buf. Read more

default fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
1.6.0
[src]

Read the exact number of bytes required to fill buf. Read more

default fn by_ref(&mut self) -> &mut Self
1.0.0
[src]

Creates a "by reference" adaptor for this instance of Read. Read more

default fn bytes(self) -> Bytes<Self>
1.0.0
[src]

Transforms this Read instance to an [Iterator] over its bytes. Read more

default fn chain<R>(self, next: R) -> Chain<Self, R> where
    R: Read
1.0.0
[src]

Creates an adaptor which will chain this stream with another. Read more

default fn take(self, limit: u64) -> Take<Self>
1.0.0
[src]

Creates an adaptor which will read at most limit bytes from it. Read more

Auto Trait Implementations

impl<T> Send for BitCursor<T> where
    T: Send

impl<T> Sync for BitCursor<T> where
    T: Sync

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]