#util #strings #reader

stringreader

Provides a wrapper for strings so that they can be consumed via the std::io::Read trait

2 releases

0.1.1 Sep 14, 2017
0.1.0 Sep 10, 2017

#5 in #strings

Download history 251/week @ 2019-12-02 153/week @ 2019-12-09 160/week @ 2019-12-16 65/week @ 2019-12-23 109/week @ 2019-12-30 79/week @ 2020-01-06 157/week @ 2020-01-13 103/week @ 2020-01-20 169/week @ 2020-01-27 164/week @ 2020-02-03 164/week @ 2020-02-10 201/week @ 2020-02-17 225/week @ 2020-02-24 156/week @ 2020-03-02 464/week @ 2020-03-09 179/week @ 2020-03-16

881 downloads per month
Used in 5 crates

MIT license

4KB

Rust StringReader

Build Status

Provides a wrapper for strings so that they can be consumed via the std::io::Read trait. This is especially useful when writing tests.

Deprecation

This create is deprecated. std::io::Read is implemented for &'a [u8], which you can get from a String using the as_bytes method.

Example

use std::io::{Read, BufRead, BufReader};
use stringreader::StringReader;

let mut streader = StringReader::new("Line 1\nLine 2");
let mut bufreader = BufReader::new(streader);
let mut buffer = String::new();

bufreader.read_line(&mut buffer).unwrap();
println!("{}", buffer);

Prints "Line 1\n".

Usage

Cargo.toml:

[dependencies]
stringreader = "*"

lib.rs/main.rs:

extern crate stringreader;

use stringreader::StringReader;

// ...
let mut reader = StringReader::new("this is a test");
// ...

No runtime deps