Crate rhai_env

Crate rhai_env 

Source
Expand description

§About rhai-env

License crates.io crates.io API Docs

This crate provides inspection and manipulation utilties of the process’s environment for the Rhai scripting language.

This crate is heavily inspired by rhai-fs.

§Usage

§Cargo.toml

[dependencies]
rhai-env = "0.1.0"

§Rhai script

let foo = read_env("FOO");
set_env("BAR", "blah");

§Rust source

use rhai::{Engine, EvalAltResult};
use rhai::packages::Package;
use rhai_env::EnvironmentPackage;

fn main() -> Result<(), Box<EvalAltResult>> {
    // Create Rhai scripting engine
    let mut engine = Engine::new();

    // Create environment package and add the package into the engine
    let package = EnvironmentPackage::new();
    package.register_into_engine(&mut engine);

    // Print the value of the environment variable `PATH`.
    let value = engine.eval::<String>(r#"env("PATH")"#)?;
    println!("{}", value);

    Ok(())
}

§Features

FeatureDefaultDescription
no_indexdisabledEnables support for no_index builds of Rhai
syncdisabledEnables support for sync builds of Rhai
metadatadisabledEnables support for generating package documentation

§API

The following functions are defined in this package:

§env(key: &str) -> String

Fetches the environment variable key from the current process.

§envs() -> Map

Fetches all environment variables.

§set_env(key: &str, value: &str)

Sets the environment variable key to the value value for the currently running process.

Structs§

EnvironmentPackage
Package for filesystem manipulation operations.