fuchsia_fuzzctl_test/
writer.rsuse fuchsia_fuzzctl::OutputSink;
use std::cell::RefCell;
use std::env;
use std::fmt::{Debug, Display};
use std::io::{stdout, Write};
use std::rc::Rc;
#[derive(Debug)]
pub struct BufferSink {
data: Rc<RefCell<Vec<u8>>>,
echo: bool,
}
impl BufferSink {
pub fn new(data: Rc<RefCell<Vec<u8>>>) -> Self {
let echo = env::var("FFX_FUZZ_TEST_ECHO_OUTPUT").is_ok();
Self { data, echo }
}
}
impl Clone for BufferSink {
fn clone(&self) -> Self {
Self { data: Rc::clone(&self.data), echo: self.echo }
}
}
impl OutputSink for BufferSink {
fn write_all(&self, buf: &[u8]) {
if self.echo {
let _ = stdout().write_all(buf);
}
let mut data = self.data.borrow_mut();
data.extend_from_slice(buf);
}
fn print<D: Display>(&self, message: D) {
self.write_all(message.to_string().as_bytes());
}
fn error<D: Display>(&self, message: D) {
self.write_all(message.to_string().as_bytes());
}
}