#string #reader #utils #io-read

stringreader

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

2 releases

Uses old Rust 2015

0.1.1 Sep 14, 2017
0.1.0 Sep 10, 2017

#1640 in Rust patterns

Download history 553/week @ 2024-09-01 395/week @ 2024-09-08 489/week @ 2024-09-15 483/week @ 2024-09-22 746/week @ 2024-09-29 401/week @ 2024-10-06 696/week @ 2024-10-13 424/week @ 2024-10-20 759/week @ 2024-10-27 922/week @ 2024-11-03 1174/week @ 2024-11-10 701/week @ 2024-11-17 941/week @ 2024-11-24 865/week @ 2024-12-01 1275/week @ 2024-12-08 868/week @ 2024-12-15

3,996 downloads per month
Used in 21 crates (16 directly)

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