mirror of
https://github.com/nushell/nushell.git
synced 2025-04-22 20:28:22 +02:00
# Description The second `Value` is redundant and will consume five extra bytes on each transmission of a custom value to/from a plugin. # User-Facing Changes This is a breaking change to the plugin protocol. The [example in the protocol reference](https://www.nushell.sh/contributor-book/plugin_protocol_reference.html#value) becomes ```json { "Custom": { "val": { "type": "PluginCustomValue", "name": "database", "data": [36, 190, 127, 40, 12, 3, 46, 83], "notify_on_drop": true }, "span": { "start": 320, "end": 340 } } } ``` instead of ```json { "CustomValue": { ... } } ``` # After Submitting Update plugin protocol reference
76 lines
1.8 KiB
Rust
76 lines
1.8 KiB
Rust
use super::NuDataFrame;
|
|
use nu_protocol::{ast::Operator, CustomValue, ShellError, Span, Value};
|
|
|
|
// CustomValue implementation for NuDataFrame
|
|
impl CustomValue for NuDataFrame {
|
|
fn typetag_name(&self) -> &'static str {
|
|
"dataframe"
|
|
}
|
|
|
|
fn typetag_deserialize(&self) {
|
|
unimplemented!("typetag_deserialize")
|
|
}
|
|
|
|
fn clone_value(&self, span: nu_protocol::Span) -> Value {
|
|
let cloned = NuDataFrame {
|
|
df: self.df.clone(),
|
|
from_lazy: false,
|
|
};
|
|
|
|
Value::custom(Box::new(cloned), span)
|
|
}
|
|
|
|
fn type_name(&self) -> String {
|
|
self.typetag_name().to_string()
|
|
}
|
|
|
|
fn to_base_value(&self, span: Span) -> Result<Value, ShellError> {
|
|
let vals = self.print(span)?;
|
|
|
|
Ok(Value::list(vals, span))
|
|
}
|
|
|
|
fn as_any(&self) -> &dyn std::any::Any {
|
|
self
|
|
}
|
|
|
|
fn follow_path_int(
|
|
&self,
|
|
_self_span: Span,
|
|
count: usize,
|
|
path_span: Span,
|
|
) -> Result<Value, ShellError> {
|
|
self.get_value(count, path_span)
|
|
}
|
|
|
|
fn follow_path_string(
|
|
&self,
|
|
_self_span: Span,
|
|
column_name: String,
|
|
path_span: Span,
|
|
) -> Result<Value, ShellError> {
|
|
let column = self.column(&column_name, path_span)?;
|
|
Ok(column.into_value(path_span))
|
|
}
|
|
|
|
fn partial_cmp(&self, other: &Value) -> Option<std::cmp::Ordering> {
|
|
match other {
|
|
Value::Custom { val, .. } => val
|
|
.as_any()
|
|
.downcast_ref::<Self>()
|
|
.and_then(|other| self.is_equal(other)),
|
|
_ => None,
|
|
}
|
|
}
|
|
|
|
fn operation(
|
|
&self,
|
|
lhs_span: Span,
|
|
operator: Operator,
|
|
op: Span,
|
|
right: &Value,
|
|
) -> Result<Value, ShellError> {
|
|
self.compute_with_value(lhs_span, operator, op, right)
|
|
}
|
|
}
|