#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

#1250 in Rust patterns

Download history 723/week @ 2024-11-15 783/week @ 2024-11-22 1053/week @ 2024-11-29 1173/week @ 2024-12-06 972/week @ 2024-12-13 376/week @ 2024-12-20 307/week @ 2024-12-27 558/week @ 2025-01-03 1087/week @ 2025-01-10 1094/week @ 2025-01-17 980/week @ 2025-01-24 1000/week @ 2025-01-31 1229/week @ 2025-02-07 729/week @ 2025-02-14 981/week @ 2025-02-21 1300/week @ 2025-02-28

4,468 downloads per month
Used in 22 crates (17 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