Struct fax::ByteReader

source ·
pub struct ByteReader<R> { /* private fields */ }

Implementations§

source§

impl<E, R: Iterator<Item = Result<u8, E>>> ByteReader<R>

source

pub fn new(read: R) -> Result<Self, E>

Construct a new ByteReader from an iterator of u8

source

pub fn print_remaining(&mut self)

Print the remaining data

Note: For debug purposes only, not part of the API.

Examples found in repository?
examples/validate.rs (line 31)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
fn main() {
    let mut args = std::env::args().skip(1);
    let input: String = args.next().unwrap();
    let output = args.next().unwrap();

    let data = fs::read(&input).unwrap();
    let reference_data = fs::read(&output).unwrap();
    let mut parts = data.splitn(3, |&b| b == b'\n');
    assert_eq!(parts.next().unwrap(), b"P4");
    let mut size = parts.next().unwrap().splitn(2, |&b| b == b' ');
    let width: u16 = std::str::from_utf8(size.next().unwrap()).unwrap().parse().unwrap();
    let height: u16 = std::str::from_utf8(size.next().unwrap()).unwrap().parse().unwrap();

    //let writer = VecWriter::new();
    let writer = Validator { reader: slice_reader(&reference_data) };
    let mut encoder = Encoder::new(writer);
    
    for (y, line) in parts.next().unwrap().chunks((width as usize + 7) / 8).enumerate().take(height as _) {
        println!("\nline {}", y);
        let line = slice_bits(line).take(width as usize)
        .map(|b| match b {
            false => Color::Black,
            true => Color::White
        });
        encoder.encode_line(line, width).unwrap();
    }
    let mut writer = encoder.finish().unwrap();
    writer.reader.print_remaining();
    

    //let (data, _) = encoder.into_writer().finish();
    //fs::write(&output, &data).unwrap();
}
source

pub fn print_peek(&self)

Trait Implementations§

source§

impl<E, R: Iterator<Item = Result<u8, E>>> BitReader for ByteReader<R>

§

type Error = E

source§

fn peek(&self, bits: u8) -> Option<u16>

look at the next (up to 16) bits of data Read more
source§

fn consume(&mut self, bits: u8) -> Result<(), E>

Consume the given amount of bits from the input.
source§

fn bits_to_byte_boundary(&self) -> u8

source§

fn expect(&mut self, bits: Bits) -> Result<(), Option<Bits>>

Assert that the next bits matches the given pattern. Read more

Auto Trait Implementations§

§

impl<R> Freeze for ByteReader<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for ByteReader<R>
where R: RefUnwindSafe,

§

impl<R> Send for ByteReader<R>
where R: Send,

§

impl<R> Sync for ByteReader<R>
where R: Sync,

§

impl<R> Unpin for ByteReader<R>
where R: Unpin,

§

impl<R> UnwindSafe for ByteReader<R>
where R: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.