rust-electrum-client/src/test_stream.rs
Alekos Filini 7b4e99e80c
Revert "Move to async I/O with Tokio"
This reverts commit e1dbfd7ceb.
2020-07-09 16:11:52 +02:00

34 lines
593 B
Rust

use std::io::{Read, Result, Write};
use std::fs::File;
pub struct TestStream {
pub file: File,
pub buffer: Vec<u8>,
}
impl TestStream {
pub fn new(file: File) -> Self {
TestStream {
file,
buffer: Vec::new(),
}
}
}
impl Read for TestStream {
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
self.file.read(buf)
}
}
impl Write for TestStream {
fn write(&mut self, buf: &[u8]) -> Result<usize> {
self.buffer.write(buf)
}
fn flush(&mut self) -> Result<()> {
self.buffer.flush()
}
}