rune
rune copied to clipboard
request: add std::env::var
I want to write some rune script to get os environment, but I dont know how to read environtment variables of OS. Is there a missing?
No, not yet!
But it's pretty easy to write a module which does anything you want, including getting environment variables. See one of these for inspiration: https://github.com/rune-rs/rune/tree/main/crates/rune-modules/src
This is what I use:
use rune::{ContextError, Module};
use rune::runtime::Object;
pub fn env() -> Object {
let mut map = Object::new();
std::env::vars().for_each(|(k, v)| {
map.insert(k.into(), v.into());
});
map
}
pub fn module() -> Result<Module, ContextError> {
let mut module = Module::with_crate("sys");
module.function(["env"], env)?;
Ok(module)
}