mirror of
https://github.com/nushell/nushell.git
synced 2025-07-14 21:35:58 +02:00
# Description This keeps plugin custom values that have requested drop notification around during the lifetime of a plugin call / stream by sending them to a channel that gets persisted during the lifetime of the call. Before this change, it was very likely that the drop notification would be sent before the plugin ever had a chance to handle the value it received. Tests have been added to make sure this works - see the `custom_values` plugin. cc @ayax79 # User-Facing Changes This is basically just a bugfix, just a slightly big one. However, I did add an `as_mut_any()` function for custom values, to avoid having to clone them. This is a breaking change.
51 lines
1.3 KiB
Rust
51 lines
1.3 KiB
Rust
use super::NuLazyFrame;
|
|
use nu_protocol::{record, CustomValue, ShellError, Span, Value};
|
|
|
|
// CustomValue implementation for NuDataFrame
|
|
impl CustomValue for NuLazyFrame {
|
|
fn typetag_name(&self) -> &'static str {
|
|
"lazyframe"
|
|
}
|
|
|
|
fn typetag_deserialize(&self) {
|
|
unimplemented!("typetag_deserialize")
|
|
}
|
|
|
|
fn clone_value(&self, span: nu_protocol::Span) -> Value {
|
|
let cloned = NuLazyFrame {
|
|
lazy: self.lazy.clone(),
|
|
from_eager: self.from_eager,
|
|
schema: self.schema.clone(),
|
|
};
|
|
|
|
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 optimized_plan = self
|
|
.as_ref()
|
|
.describe_optimized_plan()
|
|
.unwrap_or_else(|_| "<NOT AVAILABLE>".to_string());
|
|
|
|
Ok(Value::record(
|
|
record! {
|
|
"plan" => Value::string(self.as_ref().describe_plan(), span),
|
|
"optimized_plan" => Value::string(optimized_plan, span),
|
|
},
|
|
span,
|
|
))
|
|
}
|
|
|
|
fn as_any(&self) -> &dyn std::any::Any {
|
|
self
|
|
}
|
|
|
|
fn as_mut_any(&mut self) -> &mut dyn std::any::Any {
|
|
self
|
|
}
|
|
}
|