pub mod IO { pub type Result = Either; pub foreign "JS" fn print(message: String) { process.stdout.write(message); } pub struct File; pub trait Read { fn read(self, count: usize, target: Vec) -> Result; } impl Read for File { foreign "JS" fn read(self, count, target) -> Result { import * as fs from "fs" try { return Ok(fs.readSync(self.fd, target, 0, count, null)); } catch (e) { return Err(e.code); } } } } // IO::print("Hello, world!");