4 releases

0.1.3 Oct 25, 2023
0.1.2 Dec 3, 2022
0.1.1 Nov 2, 2022
0.1.0 Oct 24, 2022
0.0.1 Oct 12, 2022

#144 in Embedded development

Download history 200/week @ 2024-07-27 109/week @ 2024-08-03 119/week @ 2024-08-10 107/week @ 2024-08-17 147/week @ 2024-08-24 110/week @ 2024-08-31 195/week @ 2024-09-07 98/week @ 2024-09-14 117/week @ 2024-09-21 101/week @ 2024-09-28 46/week @ 2024-10-05 68/week @ 2024-10-12 56/week @ 2024-10-19 113/week @ 2024-10-26 121/week @ 2024-11-02 107/week @ 2024-11-09

403 downloads per month
Used in 7 crates (6 directly)

MIT/Apache

28KB
452 lines

About rhai-fs

License crates.io crates.io API Docs

This crate provides filesystem access for the Rhai scripting language.

Usage

Cargo.toml

[dependencies]
rhai-fs = "0.1.2"

Rhai script

// Create a file or open and truncate if file is already created
let file = open_file("example.txt");
let blob_buf = file.read_blob();
print("file contents: " + blob_buf);
blob_buf.write_utf8(0..=0x20, "foobar");
print("new file contents: " + blob_buf);
file.write(blob_buf);

Rust source

use rhai::{Engine, EvalAltResult};
use rhai::packages::Package;
use rhai_fs::FilesystemPackage;

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

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

    // Print the contents of the file `Cargo.toml`.
    let contents = engine.eval::<String>(r#"open_file("Cargo.toml", "r").read_string()"#)?;
    println!("{}", contents);

    Ok(())
}

Features

Feature Default Description
no_index disabled Enables support for no_index builds of Rhai
sync disabled Enables support for sync builds of Rhai
metadata disabled Enables support for generating package documentation

Dependencies

~6.5MB
~116K SLoC