1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
//! The `std::io` module.

use crate::{ContextError, Module};
use std::fmt;
use std::fmt::Write as _;

/// Construct the `std::io` module.
pub fn module() -> Result<Module, ContextError> {
    let mut module = Module::new(&["std", "io"]);
    module.ty(&["Error"]).build::<std::io::Error>()?;
    module.inst_fn(crate::STRING_DISPLAY, format_io_error)?;
    Ok(module)
}

fn format_io_error(error: &std::io::Error, buf: &mut String) -> fmt::Result {
    write!(buf, "{}", error)
}