artichoke_core/
io.rs

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
30
//! I/O read and write APIs.

/// Perform I/O external to the interpreter.
pub trait Io {
    /// Concrete error type for errors encountered when reading and writing.
    type Error;

    /// Writes the given bytes to the interpreter stdout stream.
    ///
    /// # Errors
    ///
    /// If the output stream encounters an error, an error is returned.
    fn print(&mut self, message: &[u8]) -> Result<(), Self::Error>;

    /// Writes the given bytes to the interpreter stdout stream followed by a
    /// newline.
    ///
    /// The default implementation uses two calls to [`print`].
    ///
    /// # Errors
    ///
    /// If the output stream encounters an error, an error is returned.
    ///
    /// [`print`]: Self::print
    fn puts(&mut self, message: &[u8]) -> Result<(), Self::Error> {
        self.print(message)?;
        self.print(b"\n")?;
        Ok(())
    }
}