| Crates.io | rhai-rusp |
| lib.rs | rhai-rusp |
| version | 1.0.1 |
| created_at | 2025-01-08 15:40:42.501863+00 |
| updated_at | 2025-06-20 15:54:36.104605+00 |
| description | Rhai bindings for the Rust USP toolkit |
| homepage | |
| repository | https://github.com/axiros/rusp |
| max_upload_size | |
| id | 1508697 |
| size | 142,468 |
rhai-ruspThis crate has been proudly sponsored by Axiros, a market leader in device management and monitoring solutions:
rhai-rusp is a new approach to address your USP protocol needs by
providing Rhai bindings for the rusp-lib crate, thus providing scripting capabilities
to USP in Rhai for either standalone runners or Rust applications which can
embed the Rhai interpreter together with the rhai-rusp bindings.
rhai-rusp?rhai-rusp can be used as a library in your own Rust applications to embed a
Rhai interpreter. To use rhai-rusp as a library, you simply need to add the
rhai-rusp crate to your Cargo.toml as dependency:
[dependencies]
rhai-rusp = "1"
The usual steps to embed a Rhai interpreter with rusp support are:
rhai::Engine::new()rusp bindings into the namespace per
engine.register_static_module("rusp", RuspPackage::new().as_shared_module())Rhai code into an AST via engine.compile(contents)Rhai AST via engine.run_ast(ast)There's also the rusp-run binary as part of the rusp crate which you can install via:
# cargo install rusp
The documentation provides plenty of examples inside the various modules of how to use them. But here are some practical examples anyway to give you a taste:
let msg = rusp::load_msg("msg.pb");
print(msg);
loads and prints a Protobuf encoded USP Message as a readable JSON structure.
let record = rusp::load_record("record.pb");
print(record.to_c_array());
loads and prints a Protobuf encoded USP Record as a C array which can e.g. be embedded into unit tests.
let body = rusp::get_builder()
.with_params(["Device."])
.with_max_depth(2)
.build();
let msg = rusp::msg_builder()
.with_msg_id("Foo")
.with_body(body)
.build();
let record = rusp::record_builder()
.with_version("1.3")
.with_to_id("proto::to")
.with_from_id("proto::from")
.with_no_session_context_payload(msg)
.build();
builds a body with a Get request, wraps it in a USP Msg and encapsulates that in a USP Record.
The same can since 0.98 also be achieved much more compactly via:
let record = rusp::get_builder()
.with_params(["Device."])
.with_max_depth(2)
.build()
.as_msg_builder()
.with_msg_id("Foo")
.as_no_session_record_builder()
.with_version("1.3")
.with_to_id("proto::to")
.with_from_id("proto::from")
.build();
You may use this crate however you like under the BSD 3-Clause Licence.
Feel free to spread the word or drop us a note if you like it. Collaboration on this crate is highly welcome as are pull requests in our GitHub repo.
If you are in need of software for USP management software (agent, controller or testing) or expertise please get in touch with us. We're also happy to solve all other device management and monitoring needs!