#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

#1248 in Rust patterns

Download history 1426/week @ 2024-03-13 997/week @ 2024-03-20 665/week @ 2024-03-27 719/week @ 2024-04-03 1006/week @ 2024-04-10 818/week @ 2024-04-17 630/week @ 2024-04-24 1075/week @ 2024-05-01 801/week @ 2024-05-08 715/week @ 2024-05-15 1382/week @ 2024-05-22 1223/week @ 2024-05-29 1388/week @ 2024-06-05 752/week @ 2024-06-12 688/week @ 2024-06-19 674/week @ 2024-06-26

3,672 downloads per month
Used in 18 crates (14 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