thoughtram / read-ext

Extensions for Rusts standard Read trait

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

#Extensions for Rusts standard Read trait

This adds read_into_string and read_into_vec as specified in this RFC.

##How to use

extern crate readext;

use std::io::{Cursor};
use readext::ReadExt;

#[test]
fn can_read_into_string () {
    let bytes = b"hello";
    let mut input = Cursor::new(bytes as &[u8]);
    let s = input.read_into_string().unwrap();
    assert_eq!(s, "hello");
}


#[test]
fn can_read_into_vec () {
    let bytes = b"hello";
    let mut input = Cursor::new(bytes as &[u8]);
    let s = input.read_into_vec().unwrap();
    assert_eq!(s.len(), 5);
}

About

Extensions for Rusts standard Read trait

License:MIT License


Languages

Language:Rust 100.0%