77 breaking releases

new 0.100.0 Nov 13, 2024
0.98.0 Sep 18, 2024
0.96.1 Jul 29, 2024
0.91.0 Mar 5, 2024
0.12.0 Mar 31, 2020

#489 in Network programming

Download history 1002/week @ 2024-07-30 528/week @ 2024-08-06 542/week @ 2024-08-13 1033/week @ 2024-08-20 742/week @ 2024-08-27 594/week @ 2024-09-03 671/week @ 2024-09-10 1062/week @ 2024-09-17 1309/week @ 2024-09-24 929/week @ 2024-10-01 982/week @ 2024-10-08 1370/week @ 2024-10-15 791/week @ 2024-10-22 856/week @ 2024-10-29 825/week @ 2024-11-05 977/week @ 2024-11-12

3,694 downloads per month
Used in 87 crates (85 directly)

MIT and maybe CC-PDDC

1.5MB
37K SLoC

nu-plugin

This crate provides the API for Nushell plugins. See the book for more information on how to get started.


lib.rs:

Nu Plugin: Plugin library for Nushell

This crate contains the interface necessary to build Nushell plugins in Rust. Additionally, it contains public, but undocumented, items used by Nushell itself to interface with Nushell plugins. This documentation focuses on the interface needed to write an independent plugin.

Nushell plugins are stand-alone applications that communicate with Nushell over stdin and stdout using a standardizes serialization framework to exchange the typed data that Nushell commands utilize natively.

A typical plugin application will define a struct that implements the Plugin trait and then, in its main method, pass that Plugin to the [serve_plugin()] function, which will handle all of the input and output serialization when invoked by Nushell.

use nu_plugin::{EvaluatedCall, MsgPackSerializer, serve_plugin};
use nu_plugin::{EngineInterface, Plugin, PluginCommand, SimplePluginCommand};
use nu_protocol::{LabeledError, Signature, Value};

struct MyPlugin;
struct MyCommand;

impl Plugin for MyPlugin {
    fn version(&self) -> String {
        env!("CARGO_PKG_VERSION").into()
    }

    fn commands(&self) -> Vec<Box<dyn PluginCommand<Plugin = Self>>> {
        vec![Box::new(MyCommand)]
    }
}

impl SimplePluginCommand for MyCommand {
    type Plugin = MyPlugin;

    fn name(&self) -> &str {
        "my-command"
    }

    fn description(&self) -> &str {
        todo!();
    }

    fn signature(&self) -> Signature {
        todo!();
    }

    fn run(
        &self,
        plugin: &MyPlugin,
        engine: &EngineInterface,
        call: &EvaluatedCall,
        input: &Value
    ) -> Result<Value, LabeledError> {
        todo!();
    }
}

fn main() {
   serve_plugin(&MyPlugin{}, MsgPackSerializer)
}

Nushell's source tree contains a Plugin Example that demonstrates the full range of plugin capabilities.

Dependencies

~22–52MB
~1M SLoC