Embed the nu engine in your rust application
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Go to file
trivernis 2edbf12a42
chore: Release embed-nu version 0.5.4
2 weeks ago
src Re-export nu_engine 2 weeks ago
tests Update nu 1 month ago
.gitignore Add state builder with command state 6 months ago
Cargo.toml chore: Release embed-nu version 0.5.4 2 weeks ago
README.md Add support for adding custom commands to the engine 5 months ago



embed-nu can be used to call nu scripts and expressions from within your rust application. This crate provides a wrapper around the nu engine to easily build the nu execution context, parse scripts and call functions. As this crate includes nu as a dependency calls to nu don't have the overhead of calling an external application.

Example Usage

use embed_nu::{rusty_value::*, CommandGroupConfig, Context, NewEmpty, PipelineData};

fn main() {
  let mut ctx = Context::builder()

  // eval a nu expression
  let pipeline = ctx
          r#"echo "Hello World from this eval""#,

  // print the pipeline of this expression. In this case
  // this pipeline contains the text of the echo expression
  // as it's the last expressin 

  // this eval put's the function definition of hello into scope 
      def hello [] {
          echo "Hello World from this script";
          echo # dummy echo so I don't have to print the output

  // hello can now be called as a function
  ctx.call_fn("hello", [] as [String; 0]).unwrap();

Converting data into nu values

This crate uses rusty-value to convert any rust data type into nu values.

use embed_nu::{rusty_value::*, IntoValue};

// derive rusty value
struct MyStruct {
    foo: String,
    bar: usize,

fn main() {
  let instance = MyStruct {
    foo: String::from("foo"),
    bar: 12
  // convert this struct into a nu value
  // this is also done implicitly when passing the value to the nu context
  // as function arguments or variables
  let value = instance.into_value();