3 releases

Uses new Rust 2021

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

#498 in Embedded development

Download history 20/week @ 2022-10-07 5/week @ 2022-10-14 25/week @ 2022-10-21 23/week @ 2022-10-28 10/week @ 2022-11-04 5/week @ 2022-11-11 5/week @ 2022-11-18 28/week @ 2022-12-02 6/week @ 2022-12-09 1/week @ 2022-12-16 2/week @ 2022-12-23 1/week @ 2022-12-30 4/week @ 2023-01-06 15/week @ 2023-01-13 219/week @ 2023-01-20

239 downloads per month
Used in 3 crates (2 directly)

MIT/Apache

26KB
421 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 it 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
metadata disabled Enables support for generating package documentation

Dependencies

~4MB
~77K SLoC