1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
//! Configurable output sinks used by I/O BIF stubs. use std::io::Write; /// Output target for `io` module BIFs. pub trait IoSink: Send + Sync { /// Write bytes to the sink. fn write(&self, bytes: &[u8]); } /// Default output sink that intentionally discards all bytes. #[derive(Debug, Default)] pub struct NullSink; impl IoSink for NullSink { fn write(&self, _bytes: &[u8]) {} } /// Output sink that writes directly to process stdout. #[derive(Debug, Default)] pub struct StdoutSink; impl IoSink for StdoutSink { fn write(&self, bytes: &[u8]) { let mut stdout = std::io::stdout().lock(); let _ = stdout.write_all(bytes); let _ = stdout.flush(); } }