artichoke_core/io.rs
1//! I/O read and write APIs.
2
3/// Perform I/O external to the interpreter.
4pub trait Io {
5 /// Concrete error type for errors encountered when reading and writing.
6 type Error;
7
8 /// Writes the given bytes to the interpreter stdout stream.
9 ///
10 /// # Errors
11 ///
12 /// If the output stream encounters an error, an error is returned.
13 fn print(&mut self, message: &[u8]) -> Result<(), Self::Error>;
14
15 /// Writes the given bytes to the interpreter stdout stream followed by a
16 /// newline.
17 ///
18 /// The default implementation uses two calls to [`print`].
19 ///
20 /// # Errors
21 ///
22 /// If the output stream encounters an error, an error is returned.
23 ///
24 /// [`print`]: Self::print
25 fn puts(&mut self, message: &[u8]) -> Result<(), Self::Error> {
26 self.print(message)?;
27 self.print(b"\n")?;
28 Ok(())
29 }
30}