forked from extern/nushell
# Description Continuing from #12568, this PR further reduces the size of `Expr` from 64 to 40 bytes. It also reduces `Expression` from 128 to 96 bytes and `Type` from 32 to 24 bytes. This was accomplished by: - for `Expr` with multiple fields (e.g., `Expr::Thing(A, B, C)`), merging the fields into new AST struct types and then boxing this struct (e.g. `Expr::Thing(Box<ABC>)`). - replacing `Vec<T>` with `Box<[T]>` in multiple places. `Expr`s and `Expression`s should rarely be mutated, if at all, so this optimization makes sense. By reducing the size of these types, I didn't notice a large performance improvement (at least compared to #12568). But this PR does reduce the memory usage of nushell. My config is somewhat light so I only noticed a difference of 1.4MiB (38.9MiB vs 37.5MiB). --------- Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
50 lines
1.3 KiB
Rust
50 lines
1.3 KiB
Rust
use nu_plugin::{EngineInterface, EvaluatedCall, SimplePluginCommand};
|
|
use nu_protocol::{Category, LabeledError, Signature, Type, Value};
|
|
|
|
use crate::ExamplePlugin;
|
|
|
|
pub struct Config;
|
|
|
|
impl SimplePluginCommand for Config {
|
|
type Plugin = ExamplePlugin;
|
|
|
|
fn name(&self) -> &str {
|
|
"example config"
|
|
}
|
|
|
|
fn usage(&self) -> &str {
|
|
"Show plugin configuration"
|
|
}
|
|
|
|
fn extra_usage(&self) -> &str {
|
|
"The configuration is set under $env.config.plugins.example"
|
|
}
|
|
|
|
fn signature(&self) -> Signature {
|
|
Signature::build(self.name())
|
|
.category(Category::Experimental)
|
|
.input_output_type(Type::Nothing, Type::table())
|
|
}
|
|
|
|
fn search_terms(&self) -> Vec<&str> {
|
|
vec!["example", "configuration"]
|
|
}
|
|
|
|
fn run(
|
|
&self,
|
|
_plugin: &ExamplePlugin,
|
|
engine: &EngineInterface,
|
|
call: &EvaluatedCall,
|
|
_input: &Value,
|
|
) -> Result<Value, LabeledError> {
|
|
let config = engine.get_plugin_config()?;
|
|
match config {
|
|
Some(config) => Ok(config.clone()),
|
|
None => Err(LabeledError::new("No config sent").with_label(
|
|
"configuration for this plugin was not found in `$env.config.plugins.example`",
|
|
call.head,
|
|
)),
|
|
}
|
|
}
|
|
}
|