Skip to content

Add FailingReader<R:Reader> to make every Reader fail on errors #12368

Closed
@mneumann

Description

@mneumann

In case you want to fail upon an I/O error, you can wrap every Reader with a FailingReader.

use std::io::{Reader,IoResult};

pub struct FailingReader<R> {
    priv inner: R
}

impl<R> FailingReader<R> {
    pub fn new(inner: R) -> FailingReader<R> {
        FailingReader { inner: inner }
    }
}

impl<R: Reader> Reader for FailingReader<R> {
    fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> {
        let res = self.inner.read(buf);
        if res.is_err() { fail!() }
        res
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions