Wraps an existing reader and copies the read bytes into it's own buffer
Add the following line to your Cargo.toml
:
[dependencies]
tap-reader = "1"
To use, add the following lines to your crate root (src/lib.rs, src/main.rs, etc.)
``` extern crate tap_reader;
use tap_reader::Tap; ```
``` extern crate tapreader; extern crate serdejson; extern crate serde;
use std::error::Error; use std::io::Cursor; use tap_reader::Tap;
struct Foo { foo: String, bar: usize, }
fn main() -> Result<(), Box
let foo: Foo = match serde_json::from_reader(&mut reader) {
Ok(foo) => foo,
Err(e) => {
eprintln!("Error serializing Foo from input: '{}'\n error was: {}",
String::from_utf8_lossy(&reader.bytes),
e.description());
return Err(());
}
};
assert_eq!(
foo,
Foo {
foo: "hello, world!".to_string(),
bar: 42
}
);
assert_eq!(reader.bytes, bytes);
Ok(())
} ```