Crates.io | stringreader |
lib.rs | stringreader |
version | 0.1.1 |
source | src |
created_at | 2017-09-10 13:33:44.396623 |
updated_at | 2017-09-14 18:55:24.098713 |
description | Provides a wrapper for strings so that they can be consumed via the std::io::Read trait. |
homepage | https://github.com/Leopard2A5/rust-stringreader |
repository | |
max_upload_size | |
id | 31285 |
size | 4,427 |
Provides a wrapper for strings so that they can be consumed via the std::io::Read trait. This is especially useful when writing tests.
This create is deprecated. std::io::Read
is implemented for &'a [u8]
, which you can get from a String using the as_bytes
method.
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".
Cargo.toml:
[dependencies]
stringreader = "*"
lib.rs/main.rs:
extern crate stringreader;
use stringreader::StringReader;
// ...
let mut reader = StringReader::new("this is a test");
// ...