#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Stream {
Stdout,
Stderr,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum RejectionEvent {
Rejected,
Handled,
}
pub trait Host {
fn write(&mut self, stream: Stream, text: &[u8]) {
use std::io::Write;
match stream {
Stream::Stdout => {
let mut out = std::io::stdout().lock();
let _ = out.write_all(text);
let _ = out.flush();
}
Stream::Stderr => {
let mut out = std::io::stderr().lock();
let _ = out.write_all(text);
let _ = out.flush();
}
}
}
fn now_ms(&mut self) -> f64 {
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.map_or(0.0, |elapsed| elapsed.as_millis() as f64)
}
fn local_tz_offset_minutes(&mut self, _utc_ms: f64) -> i32 {
0
}
fn random_seed(&mut self) -> u64 {
crate::clock::time_seed()
}
fn promise_rejection(&mut self, event: RejectionEvent, promise: crate::Value) {
let _ = (event, promise);
}
fn read_file(&mut self, path: &str) -> Option<String> {
std::fs::read_to_string(path).ok()
}
fn interrupt(&mut self) -> bool {
false
}
}
#[derive(Debug, Default)]
pub struct SystemHost;
impl Host for SystemHost {}