bolt/stdlib/io.bolt

36 lines
558 B
Text
Raw Normal View History

2020-05-24 11:18:52 +02:00
pub mod IO {
2020-05-24 11:18:52 +02:00
pub type Result<T> = Either<Error, T>;
pub foreign "JS" fn print(message: String) {
process.stdout.write(message);
}
pub struct File;
2020-05-24 11:18:52 +02:00
pub trait Read {
fn read(self, count: usize, target: Vec<u8>) -> Result<usize>;
}
impl Read for File {
foreign "JS" fn read(self, count, target) -> Result<usize> {
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!");
2020-05-24 11:18:52 +02:00