Skip to content

Commit

Permalink
πŸ“ Add util functions for WASI env.
Browse files Browse the repository at this point in the history
  • Loading branch information
langyo committed Dec 25, 2023
1 parent ebf6b57 commit f1e81e0
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions packages/utils/src/types/proto/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,26 @@ impl Msg {
}
}
}

#[cfg(target_os = "wasi")]
pub mod wasi {
use super::Msg;
use anyhow::Result;

pub fn read() -> Result<Msg> {
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
let msg: Msg = serde_json::from_str(&input).unwrap();

Ok(msg)
}

pub fn write(channel: impl ToString, content: impl ToString) -> Result<()> {
println!(
"{}",
serde_json::to_string(&Msg::new(channel.to_string(), content.to_string()))?
);

Ok(())
}
}

0 comments on commit f1e81e0

Please sign in to comment.