Trait whiteread::reader::BorrowedResultExt [] [src]

pub trait BorrowedResultExt<'a, T> {
    fn none_on_too_short(self) -> BorrowedResult<'a, Option<T>>;
    fn to_owned(self) -> OwnedResult<T>;
}

Trait providing additional methods on BorrowedResult.

This trait is included in prelude.

Required Methods

Propagates an error, unless it's TooShort (returns None in that case).

Examples

Summing all integers from a file (until the end), with proper error handling.

use whiteread::{Reader, ReaderResult};
use whiteread::prelude::*;

fn sum_file() -> whiteread::ReaderResult<i64> {
    let mut reader = Reader::open("numbers.txt")?;
    let mut s: i64 = 0;
    while let Some(x) = reader.continue_().none_on_too_short()? {
        s += x
    }
    Ok(s)
}

Converts the error variant from BorrowedError to OwnedError.

See the BorrowedError and OwnedError for more details.

The conversion is also performed by the From::from implementation used by try! macro and the ? (question mark) operator, so you should rarely need this method.

Implementors