From b19da158d54fdf1f32f2ce40395a7f67a10bd242 Mon Sep 17 00:00:00 2001 From: Stefan Holderbach Date: Wed, 27 Mar 2024 22:10:56 +0100 Subject: [PATCH] Rename `Value::CustomValue` to `Value::Custom` (#12309) # 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 --- .../src/dataframe/eager/query_df.rs | 2 +- .../src/dataframe/lazy/collect.rs | 2 +- .../src/dataframe/lazy/to_lazy.rs | 2 +- .../values/nu_dataframe/custom_value.rs | 4 +- .../src/dataframe/values/nu_dataframe/mod.rs | 12 +- .../values/nu_dataframe/operations.rs | 2 +- .../values/nu_expression/custom_value.rs | 4 +- .../src/dataframe/values/nu_expression/mod.rs | 8 +- .../values/nu_lazyframe/custom_value.rs | 2 +- .../src/dataframe/values/nu_lazyframe/mod.rs | 8 +- .../values/nu_lazygroupby/custom_value.rs | 2 +- .../dataframe/values/nu_lazygroupby/mod.rs | 4 +- .../dataframe/values/nu_when/custom_value.rs | 2 +- .../src/dataframe/values/nu_when/mod.rs | 4 +- .../nu-cmd-lang/src/core_commands/describe.rs | 2 +- crates/nu-cmd-lang/src/example_support.rs | 2 +- crates/nu-color-config/src/style_computer.rs | 2 +- .../nu-command/src/conversions/into/string.rs | 2 +- .../nu-command/src/database/values/sqlite.rs | 6 +- crates/nu-command/src/debug/explain.rs | 2 +- crates/nu-command/src/filters/columns.rs | 2 +- crates/nu-command/src/filters/find.rs | 2 +- crates/nu-command/src/filters/values.rs | 2 +- crates/nu-command/src/formats/to/delimited.rs | 2 +- crates/nu-command/src/formats/to/json.rs | 2 +- crates/nu-command/src/formats/to/nuon.rs | 2 +- crates/nu-command/src/formats/to/text.rs | 2 +- crates/nu-command/src/formats/to/toml.rs | 2 +- crates/nu-command/src/formats/to/yaml.rs | 2 +- crates/nu-command/src/sort_utils.rs | 2 +- crates/nu-command/src/stor/create.rs | 2 +- crates/nu-command/src/stor/delete.rs | 2 +- crates/nu-command/src/stor/export.rs | 2 +- crates/nu-command/src/stor/import.rs | 2 +- crates/nu-command/src/stor/insert.rs | 2 +- crates/nu-command/src/stor/reset.rs | 2 +- crates/nu-command/src/stor/update.rs | 2 +- crates/nu-command/src/viewers/table.rs | 2 +- .../tests/custom_value/mod.rs | 2 +- .../src/plugin/interface/engine/tests.rs | 10 +- .../src/protocol/plugin_custom_value.rs | 18 +-- .../src/protocol/plugin_custom_value/tests.rs | 10 +- crates/nu-plugin/src/protocol/test_util.rs | 2 +- crates/nu-plugin/src/serializers/tests.rs | 2 +- crates/nu-protocol/src/value/mod.rs | 118 +++++++++--------- .../src/cool_custom_value.rs | 10 +- .../nu_plugin_custom_values/src/drop_check.rs | 2 +- .../src/second_custom_value.rs | 8 +- 48 files changed, 144 insertions(+), 148 deletions(-) diff --git a/crates/nu-cmd-dataframe/src/dataframe/eager/query_df.rs b/crates/nu-cmd-dataframe/src/dataframe/eager/query_df.rs index 7215f0adbe..4088e00afa 100644 --- a/crates/nu-cmd-dataframe/src/dataframe/eager/query_df.rs +++ b/crates/nu-cmd-dataframe/src/dataframe/eager/query_df.rs @@ -87,7 +87,7 @@ fn command( let lazy = NuLazyFrame::new(false, df_sql); let eager = lazy.collect(call.head)?; - let value = Value::custom_value(Box::new(eager), call.head); + let value = Value::custom(Box::new(eager), call.head); Ok(PipelineData::Value(value, None)) } diff --git a/crates/nu-cmd-dataframe/src/dataframe/lazy/collect.rs b/crates/nu-cmd-dataframe/src/dataframe/lazy/collect.rs index 411f563640..c27591cc1d 100644 --- a/crates/nu-cmd-dataframe/src/dataframe/lazy/collect.rs +++ b/crates/nu-cmd-dataframe/src/dataframe/lazy/collect.rs @@ -55,7 +55,7 @@ impl Command for LazyCollect { ) -> Result { let lazy = NuLazyFrame::try_from_pipeline(input, call.head)?; let eager = lazy.collect(call.head)?; - let value = Value::custom_value(Box::new(eager), call.head); + let value = Value::custom(Box::new(eager), call.head); Ok(PipelineData::Value(value, None)) } diff --git a/crates/nu-cmd-dataframe/src/dataframe/lazy/to_lazy.rs b/crates/nu-cmd-dataframe/src/dataframe/lazy/to_lazy.rs index 857be750d3..cad516b9eb 100644 --- a/crates/nu-cmd-dataframe/src/dataframe/lazy/to_lazy.rs +++ b/crates/nu-cmd-dataframe/src/dataframe/lazy/to_lazy.rs @@ -47,7 +47,7 @@ impl Command for ToLazyFrame { let df = NuDataFrame::try_from_iter(input.into_iter(), maybe_schema)?; let lazy = NuLazyFrame::from_dataframe(df); - let value = Value::custom_value(Box::new(lazy), call.head); + let value = Value::custom(Box::new(lazy), call.head); Ok(PipelineData::Value(value, None)) } diff --git a/crates/nu-cmd-dataframe/src/dataframe/values/nu_dataframe/custom_value.rs b/crates/nu-cmd-dataframe/src/dataframe/values/nu_dataframe/custom_value.rs index 5d9879a991..7bde7cb539 100644 --- a/crates/nu-cmd-dataframe/src/dataframe/values/nu_dataframe/custom_value.rs +++ b/crates/nu-cmd-dataframe/src/dataframe/values/nu_dataframe/custom_value.rs @@ -17,7 +17,7 @@ impl CustomValue for NuDataFrame { from_lazy: false, }; - Value::custom_value(Box::new(cloned), span) + Value::custom(Box::new(cloned), span) } fn type_name(&self) -> String { @@ -55,7 +55,7 @@ impl CustomValue for NuDataFrame { fn partial_cmp(&self, other: &Value) -> Option { match other { - Value::CustomValue { val, .. } => val + Value::Custom { val, .. } => val .as_any() .downcast_ref::() .and_then(|other| self.is_equal(other)), diff --git a/crates/nu-cmd-dataframe/src/dataframe/values/nu_dataframe/mod.rs b/crates/nu-cmd-dataframe/src/dataframe/values/nu_dataframe/mod.rs index 8f90966fe2..638fc543ab 100644 --- a/crates/nu-cmd-dataframe/src/dataframe/values/nu_dataframe/mod.rs +++ b/crates/nu-cmd-dataframe/src/dataframe/values/nu_dataframe/mod.rs @@ -116,15 +116,15 @@ impl NuDataFrame { } pub fn dataframe_into_value(dataframe: DataFrame, span: Span) -> Value { - Value::custom_value(Box::new(Self::new(false, dataframe)), span) + Value::custom(Box::new(Self::new(false, dataframe)), span) } pub fn into_value(self, span: Span) -> Value { if self.from_lazy { let lazy = NuLazyFrame::from_dataframe(self); - Value::custom_value(Box::new(lazy), span) + Value::custom(Box::new(lazy), span) } else { - Value::custom_value(Box::new(self), span) + Value::custom(Box::new(self), span) } } @@ -152,7 +152,7 @@ impl NuDataFrame { for value in iter { match value { - Value::CustomValue { .. } => return Self::try_from_value(value), + Value::Custom { .. } => return Self::try_from_value(value), Value::List { vals, .. } => { let record = vals .into_iter() @@ -256,7 +256,7 @@ impl NuDataFrame { pub fn get_df(value: Value) -> Result { let span = value.span(); match value { - Value::CustomValue { val, .. } => match val.as_any().downcast_ref::() { + Value::Custom { val, .. } => match val.as_any().downcast_ref::() { Some(df) => Ok(NuDataFrame { df: df.df.clone(), from_lazy: false, @@ -283,7 +283,7 @@ impl NuDataFrame { } pub fn can_downcast(value: &Value) -> bool { - if let Value::CustomValue { val, .. } = value { + if let Value::Custom { val, .. } = value { val.as_any().downcast_ref::().is_some() } else { false diff --git a/crates/nu-cmd-dataframe/src/dataframe/values/nu_dataframe/operations.rs b/crates/nu-cmd-dataframe/src/dataframe/values/nu_dataframe/operations.rs index 3fbe40806a..ff2f7b7604 100644 --- a/crates/nu-cmd-dataframe/src/dataframe/values/nu_dataframe/operations.rs +++ b/crates/nu-cmd-dataframe/src/dataframe/values/nu_dataframe/operations.rs @@ -20,7 +20,7 @@ impl NuDataFrame { ) -> Result { let rhs_span = right.span(); match right { - Value::CustomValue { val: rhs, .. } => { + Value::Custom { val: rhs, .. } => { let rhs = rhs.as_any().downcast_ref::().ok_or_else(|| { ShellError::DowncastNotPossible { msg: "Unable to create dataframe".to_string(), diff --git a/crates/nu-cmd-dataframe/src/dataframe/values/nu_expression/custom_value.rs b/crates/nu-cmd-dataframe/src/dataframe/values/nu_expression/custom_value.rs index 7d786c9f75..0859746fb9 100644 --- a/crates/nu-cmd-dataframe/src/dataframe/values/nu_expression/custom_value.rs +++ b/crates/nu-cmd-dataframe/src/dataframe/values/nu_expression/custom_value.rs @@ -19,7 +19,7 @@ impl CustomValue for NuExpression { fn clone_value(&self, span: nu_protocol::Span) -> Value { let cloned = NuExpression(self.0.clone()); - Value::custom_value(Box::new(cloned), span) + Value::custom(Box::new(cloned), span) } fn type_name(&self) -> String { @@ -54,7 +54,7 @@ fn compute_with_value( ) -> Result { let rhs_span = right.span(); match right { - Value::CustomValue { val: rhs, .. } => { + Value::Custom { val: rhs, .. } => { let rhs = rhs.as_any().downcast_ref::().ok_or_else(|| { ShellError::DowncastNotPossible { msg: "Unable to create expression".into(), diff --git a/crates/nu-cmd-dataframe/src/dataframe/values/nu_expression/mod.rs b/crates/nu-cmd-dataframe/src/dataframe/values/nu_expression/mod.rs index 3ffb7b7c2b..664beb929c 100644 --- a/crates/nu-cmd-dataframe/src/dataframe/values/nu_expression/mod.rs +++ b/crates/nu-cmd-dataframe/src/dataframe/values/nu_expression/mod.rs @@ -55,13 +55,13 @@ impl From for NuExpression { impl NuExpression { pub fn into_value(self, span: Span) -> Value { - Value::custom_value(Box::new(self), span) + Value::custom(Box::new(self), span) } pub fn try_from_value(value: Value) -> Result { let span = value.span(); match value { - Value::CustomValue { val, .. } => match val.as_any().downcast_ref::() { + Value::Custom { val, .. } => match val.as_any().downcast_ref::() { Some(expr) => Ok(NuExpression(expr.0.clone())), None => Err(ShellError::CantConvert { to_type: "lazy expression".into(), @@ -90,7 +90,7 @@ impl NuExpression { pub fn can_downcast(value: &Value) -> bool { match value { - Value::CustomValue { val, .. } => val.as_any().downcast_ref::().is_some(), + Value::Custom { val, .. } => val.as_any().downcast_ref::().is_some(), Value::List { vals, .. } => vals.iter().all(Self::can_downcast), Value::String { .. } | Value::Int { .. } | Value::Bool { .. } | Value::Float { .. } => { true @@ -144,7 +144,7 @@ impl ExtractedExpr { fn extract_exprs(value: Value) -> Result { match value { Value::String { val, .. } => Ok(ExtractedExpr::Single(col(val.as_str()))), - Value::CustomValue { .. } => NuExpression::try_from_value(value) + Value::Custom { .. } => NuExpression::try_from_value(value) .map(NuExpression::into_polars) .map(ExtractedExpr::Single), Value::List { vals, .. } => vals diff --git a/crates/nu-cmd-dataframe/src/dataframe/values/nu_lazyframe/custom_value.rs b/crates/nu-cmd-dataframe/src/dataframe/values/nu_lazyframe/custom_value.rs index fc091ada1d..0990e95663 100644 --- a/crates/nu-cmd-dataframe/src/dataframe/values/nu_lazyframe/custom_value.rs +++ b/crates/nu-cmd-dataframe/src/dataframe/values/nu_lazyframe/custom_value.rs @@ -18,7 +18,7 @@ impl CustomValue for NuLazyFrame { schema: self.schema.clone(), }; - Value::custom_value(Box::new(cloned), span) + Value::custom(Box::new(cloned), span) } fn type_name(&self) -> String { diff --git a/crates/nu-cmd-dataframe/src/dataframe/values/nu_lazyframe/mod.rs b/crates/nu-cmd-dataframe/src/dataframe/values/nu_lazyframe/mod.rs index 35f94d9c9b..f03d9f0cc8 100644 --- a/crates/nu-cmd-dataframe/src/dataframe/values/nu_lazyframe/mod.rs +++ b/crates/nu-cmd-dataframe/src/dataframe/values/nu_lazyframe/mod.rs @@ -90,9 +90,9 @@ impl NuLazyFrame { pub fn into_value(self, span: Span) -> Result { if self.from_eager { let df = self.collect(span)?; - Ok(Value::custom_value(Box::new(df), span)) + Ok(Value::custom(Box::new(df), span)) } else { - Ok(Value::custom_value(Box::new(self), span)) + Ok(Value::custom(Box::new(self), span)) } } @@ -141,7 +141,7 @@ impl NuLazyFrame { pub fn get_lazy_df(value: Value) -> Result { let span = value.span(); match value { - Value::CustomValue { val, .. } => match val.as_any().downcast_ref::() { + Value::Custom { val, .. } => match val.as_any().downcast_ref::() { Some(expr) => Ok(Self { lazy: expr.lazy.clone(), from_eager: false, @@ -164,7 +164,7 @@ impl NuLazyFrame { } pub fn can_downcast(value: &Value) -> bool { - if let Value::CustomValue { val, .. } = value { + if let Value::Custom { val, .. } = value { val.as_any().downcast_ref::().is_some() } else { false diff --git a/crates/nu-cmd-dataframe/src/dataframe/values/nu_lazygroupby/custom_value.rs b/crates/nu-cmd-dataframe/src/dataframe/values/nu_lazygroupby/custom_value.rs index cf19d72f34..0f686c6bd2 100644 --- a/crates/nu-cmd-dataframe/src/dataframe/values/nu_lazygroupby/custom_value.rs +++ b/crates/nu-cmd-dataframe/src/dataframe/values/nu_lazygroupby/custom_value.rs @@ -18,7 +18,7 @@ impl CustomValue for NuLazyGroupBy { from_eager: self.from_eager, }; - Value::custom_value(Box::new(cloned), span) + Value::custom(Box::new(cloned), span) } fn type_name(&self) -> String { diff --git a/crates/nu-cmd-dataframe/src/dataframe/values/nu_lazygroupby/mod.rs b/crates/nu-cmd-dataframe/src/dataframe/values/nu_lazygroupby/mod.rs index 88b1bb5746..e942e3be97 100644 --- a/crates/nu-cmd-dataframe/src/dataframe/values/nu_lazygroupby/mod.rs +++ b/crates/nu-cmd-dataframe/src/dataframe/values/nu_lazygroupby/mod.rs @@ -74,7 +74,7 @@ impl From for NuLazyGroupBy { impl NuLazyGroupBy { pub fn into_value(self, span: Span) -> Value { - Value::custom_value(Box::new(self), span) + Value::custom(Box::new(self), span) } pub fn into_polars(self) -> LazyGroupBy { @@ -84,7 +84,7 @@ impl NuLazyGroupBy { pub fn try_from_value(value: Value) -> Result { let span = value.span(); match value { - Value::CustomValue { val, .. } => match val.as_any().downcast_ref::() { + Value::Custom { val, .. } => match val.as_any().downcast_ref::() { Some(group) => Ok(Self { group_by: group.group_by.clone(), schema: group.schema.clone(), diff --git a/crates/nu-cmd-dataframe/src/dataframe/values/nu_when/custom_value.rs b/crates/nu-cmd-dataframe/src/dataframe/values/nu_when/custom_value.rs index b7ac53b470..60d13d7088 100644 --- a/crates/nu-cmd-dataframe/src/dataframe/values/nu_when/custom_value.rs +++ b/crates/nu-cmd-dataframe/src/dataframe/values/nu_when/custom_value.rs @@ -14,7 +14,7 @@ impl CustomValue for NuWhen { fn clone_value(&self, span: nu_protocol::Span) -> Value { let cloned = self.clone(); - Value::custom_value(Box::new(cloned), span) + Value::custom(Box::new(cloned), span) } fn type_name(&self) -> String { diff --git a/crates/nu-cmd-dataframe/src/dataframe/values/nu_when/mod.rs b/crates/nu-cmd-dataframe/src/dataframe/values/nu_when/mod.rs index 312de124ae..b33cde7483 100644 --- a/crates/nu-cmd-dataframe/src/dataframe/values/nu_when/mod.rs +++ b/crates/nu-cmd-dataframe/src/dataframe/values/nu_when/mod.rs @@ -51,13 +51,13 @@ impl From for NuWhen { impl NuWhen { pub fn into_value(self, span: Span) -> Value { - Value::custom_value(Box::new(self), span) + Value::custom(Box::new(self), span) } pub fn try_from_value(value: Value) -> Result { let span = value.span(); match value { - Value::CustomValue { val, .. } => match val.as_any().downcast_ref::() { + Value::Custom { val, .. } => match val.as_any().downcast_ref::() { Some(expr) => Ok(expr.clone()), None => Err(ShellError::CantConvert { to_type: "when expression".into(), diff --git a/crates/nu-cmd-lang/src/core_commands/describe.rs b/crates/nu-cmd-lang/src/core_commands/describe.rs index 842de60f6a..46e6e9a91e 100644 --- a/crates/nu-cmd-lang/src/core_commands/describe.rs +++ b/crates/nu-cmd-lang/src/core_commands/describe.rs @@ -281,7 +281,7 @@ fn describe_value( options: Options, ) -> Result { Ok(match value { - Value::CustomValue { val, .. } => Value::record( + Value::Custom { val, .. } => Value::record( record!( "type" => Value::string("custom", head), "subtype" => Value::string(val.type_name(), head), diff --git a/crates/nu-cmd-lang/src/example_support.rs b/crates/nu-cmd-lang/src/example_support.rs index 1efe69bc98..aa2cbb10ce 100644 --- a/crates/nu-cmd-lang/src/example_support.rs +++ b/crates/nu-cmd-lang/src/example_support.rs @@ -274,7 +274,7 @@ impl<'a> std::fmt::Debug for DebuggableValue<'a> { Value::CellPath { val, .. } => { write!(f, "CellPath({:?})", val.to_string()) } - Value::CustomValue { val, .. } => { + Value::Custom { val, .. } => { write!(f, "CustomValue({:?})", val) } Value::LazyRecord { val, .. } => { diff --git a/crates/nu-color-config/src/style_computer.rs b/crates/nu-color-config/src/style_computer.rs index 1261bd9d06..6a02cedd62 100644 --- a/crates/nu-color-config/src/style_computer.rs +++ b/crates/nu-color-config/src/style_computer.rs @@ -130,7 +130,7 @@ impl<'a> StyleComputer<'a> { TextStyle::with_style(Left, s) } Value::Closure { .. } - | Value::CustomValue { .. } + | Value::Custom { .. } | Value::Error { .. } | Value::LazyRecord { .. } => TextStyle::basic_left(), } diff --git a/crates/nu-command/src/conversions/into/string.rs b/crates/nu-command/src/conversions/into/string.rs index 7ba68dc143..84812b7dd2 100644 --- a/crates/nu-command/src/conversions/into/string.rs +++ b/crates/nu-command/src/conversions/into/string.rs @@ -226,7 +226,7 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value { }, span, ), - Value::CustomValue { val, .. } => { + Value::Custom { val, .. } => { // Only custom values that have a base value that can be converted to string are // accepted. val.to_base_value(input.span()) diff --git a/crates/nu-command/src/database/values/sqlite.rs b/crates/nu-command/src/database/values/sqlite.rs index 3ebd79de64..a25cc22140 100644 --- a/crates/nu-command/src/database/values/sqlite.rs +++ b/crates/nu-command/src/database/values/sqlite.rs @@ -69,7 +69,7 @@ impl SQLiteDatabase { pub fn try_from_value(value: Value) -> Result { let span = value.span(); match value { - Value::CustomValue { val, .. } => match val.as_any().downcast_ref::() { + Value::Custom { val, .. } => match val.as_any().downcast_ref::() { Some(db) => Ok(Self { path: db.path.clone(), ctrlc: db.ctrlc.clone(), @@ -97,7 +97,7 @@ impl SQLiteDatabase { pub fn into_value(self, span: Span) -> Value { let db = Box::new(self); - Value::custom_value(db, span) + Value::custom(db, span) } pub fn query( @@ -357,7 +357,7 @@ impl CustomValue for SQLiteDatabase { ctrlc: self.ctrlc.clone(), }; - Value::custom_value(Box::new(cloned), span) + Value::custom(Box::new(cloned), span) } fn type_name(&self) -> String { diff --git a/crates/nu-command/src/debug/explain.rs b/crates/nu-command/src/debug/explain.rs index 9854d664cd..99fb26c9cd 100644 --- a/crates/nu-command/src/debug/explain.rs +++ b/crates/nu-command/src/debug/explain.rs @@ -293,7 +293,7 @@ pub fn debug_string_without_formatting(value: &Value) -> String { Value::CellPath { val, .. } => val.to_string(), // If we fail to collapse the custom value, just print <{type_name}> - failure is not // that critical here - Value::CustomValue { val, .. } => val + Value::Custom { val, .. } => val .to_base_value(value.span()) .map(|val| debug_string_without_formatting(&val)) .unwrap_or_else(|_| format!("<{}>", val.type_name())), diff --git a/crates/nu-command/src/filters/columns.rs b/crates/nu-command/src/filters/columns.rs index e7d8eec88a..6d0535bad1 100644 --- a/crates/nu-command/src/filters/columns.rs +++ b/crates/nu-command/src/filters/columns.rs @@ -94,7 +94,7 @@ fn getcol( .into_pipeline_data(ctrlc) .set_metadata(metadata)) } - Value::CustomValue { val, .. } => { + Value::Custom { val, .. } => { // TODO: should we get CustomValue to expose columns in a more efficient way? // Would be nice to be able to get columns without generating the whole value let input_as_base_value = val.to_base_value(span)?; diff --git a/crates/nu-command/src/filters/find.rs b/crates/nu-command/src/filters/find.rs index c84bc5be89..cabfbf46b7 100644 --- a/crates/nu-command/src/filters/find.rs +++ b/crates/nu-command/src/filters/find.rs @@ -531,7 +531,7 @@ fn value_should_be_printed( | Value::Glob { .. } | Value::List { .. } | Value::CellPath { .. } - | Value::CustomValue { .. } => term_contains_value(term, &lower_value, span), + | Value::Custom { .. } => term_contains_value(term, &lower_value, span), Value::Record { val, .. } => { record_matches_term(val, columns_to_search, filter_config, term, span) } diff --git a/crates/nu-command/src/filters/values.rs b/crates/nu-command/src/filters/values.rs index aafa211f17..640ef1bb44 100644 --- a/crates/nu-command/src/filters/values.rs +++ b/crates/nu-command/src/filters/values.rs @@ -147,7 +147,7 @@ fn values( .into_pipeline_data_with_metadata(metadata, ctrlc)), Err(err) => Err(err), }, - Value::CustomValue { val, .. } => { + Value::Custom { val, .. } => { let input_as_base_value = val.to_base_value(span)?; match get_values(&[input_as_base_value], head, span) { Ok(cols) => Ok(cols diff --git a/crates/nu-command/src/formats/to/delimited.rs b/crates/nu-command/src/formats/to/delimited.rs index 22c439fbc7..a10f611f60 100644 --- a/crates/nu-command/src/formats/to/delimited.rs +++ b/crates/nu-command/src/formats/to/delimited.rs @@ -115,7 +115,7 @@ fn to_string_tagged_value( | Value::Int { .. } | Value::Duration { .. } | Value::Binary { .. } - | Value::CustomValue { .. } + | Value::Custom { .. } | Value::Filesize { .. } | Value::CellPath { .. } | Value::Float { .. } => Ok(v.clone().to_abbreviated_string(config)), diff --git a/crates/nu-command/src/formats/to/json.rs b/crates/nu-command/src/formats/to/json.rs index 5a542d8e2c..31ed623ab9 100644 --- a/crates/nu-command/src/formats/to/json.rs +++ b/crates/nu-command/src/formats/to/json.rs @@ -139,7 +139,7 @@ pub fn value_to_json_value(v: &Value) -> Result { let collected = val.collect()?; value_to_json_value(&collected)? } - Value::CustomValue { val, .. } => { + Value::Custom { val, .. } => { let collected = val.to_base_value(span)?; value_to_json_value(&collected)? } diff --git a/crates/nu-command/src/formats/to/nuon.rs b/crates/nu-command/src/formats/to/nuon.rs index 61137534ca..84b237e52e 100644 --- a/crates/nu-command/src/formats/to/nuon.rs +++ b/crates/nu-command/src/formats/to/nuon.rs @@ -158,7 +158,7 @@ pub fn value_to_string( msg_span: span, input_span: v.span(), }), - Value::CustomValue { .. } => Err(ShellError::UnsupportedInput { + Value::Custom { .. } => Err(ShellError::UnsupportedInput { msg: "custom values are currently not nuon-compatible".to_string(), input: "value originates from here".into(), msg_span: span, diff --git a/crates/nu-command/src/formats/to/text.rs b/crates/nu-command/src/formats/to/text.rs index e55c372176..873b2c8a08 100644 --- a/crates/nu-command/src/formats/to/text.rs +++ b/crates/nu-command/src/formats/to/text.rs @@ -147,7 +147,7 @@ fn local_into_string(value: Value, separator: &str, config: &Config) -> String { Value::CellPath { val, .. } => val.to_string(), // If we fail to collapse the custom value, just print <{type_name}> - failure is not // that critical here - Value::CustomValue { val, .. } => val + Value::Custom { val, .. } => val .to_base_value(span) .map(|val| local_into_string(val, separator, config)) .unwrap_or_else(|_| format!("<{}>", val.type_name())), diff --git a/crates/nu-command/src/formats/to/toml.rs b/crates/nu-command/src/formats/to/toml.rs index aae5fc8b28..383fcda95a 100644 --- a/crates/nu-command/src/formats/to/toml.rs +++ b/crates/nu-command/src/formats/to/toml.rs @@ -93,7 +93,7 @@ fn helper(engine_state: &EngineState, v: &Value) -> Result, ShellError>>()?, ), - Value::CustomValue { .. } => toml::Value::String("".to_string()), + Value::Custom { .. } => toml::Value::String("".to_string()), }) } diff --git a/crates/nu-command/src/formats/to/yaml.rs b/crates/nu-command/src/formats/to/yaml.rs index 337b4de92b..aa67f93c2b 100644 --- a/crates/nu-command/src/formats/to/yaml.rs +++ b/crates/nu-command/src/formats/to/yaml.rs @@ -95,7 +95,7 @@ pub fn value_to_yaml_value(v: &Value) -> Result { }) .collect::, ShellError>>()?, ), - Value::CustomValue { .. } => serde_yaml::Value::Null, + Value::Custom { .. } => serde_yaml::Value::Null, }) } diff --git a/crates/nu-command/src/sort_utils.rs b/crates/nu-command/src/sort_utils.rs index 0dd4f2de50..50d8256353 100644 --- a/crates/nu-command/src/sort_utils.rs +++ b/crates/nu-command/src/sort_utils.rs @@ -30,7 +30,7 @@ pub fn sort_value( Ok(Value::list(vals, span)) } - Value::CustomValue { val, .. } => { + Value::Custom { val, .. } => { let base_val = val.to_base_value(span)?; sort_value(&base_val, sort_columns, ascending, insensitive, natural) } diff --git a/crates/nu-command/src/stor/create.rs b/crates/nu-command/src/stor/create.rs index 6c00375766..3de6abd0fb 100644 --- a/crates/nu-command/src/stor/create.rs +++ b/crates/nu-command/src/stor/create.rs @@ -58,7 +58,7 @@ impl Command for StorCreate { process(table_name, span, &db, columns)?; // dbg!(db.clone()); - Ok(Value::custom_value(db, span).into_pipeline_data()) + Ok(Value::custom(db, span).into_pipeline_data()) } } diff --git a/crates/nu-command/src/stor/delete.rs b/crates/nu-command/src/stor/delete.rs index 7de9169ed9..76b1d52af4 100644 --- a/crates/nu-command/src/stor/delete.rs +++ b/crates/nu-command/src/stor/delete.rs @@ -117,7 +117,7 @@ impl Command for StorDelete { } } // dbg!(db.clone()); - Ok(Value::custom_value(db, span).into_pipeline_data()) + Ok(Value::custom(db, span).into_pipeline_data()) } } diff --git a/crates/nu-command/src/stor/export.rs b/crates/nu-command/src/stor/export.rs index ea1a6f12a0..7383fc6c8c 100644 --- a/crates/nu-command/src/stor/export.rs +++ b/crates/nu-command/src/stor/export.rs @@ -73,7 +73,7 @@ impl Command for StorExport { })?; } // dbg!(db.clone()); - Ok(Value::custom_value(db, span).into_pipeline_data()) + Ok(Value::custom(db, span).into_pipeline_data()) } } diff --git a/crates/nu-command/src/stor/import.rs b/crates/nu-command/src/stor/import.rs index f5d7360cb2..41c2a3609f 100644 --- a/crates/nu-command/src/stor/import.rs +++ b/crates/nu-command/src/stor/import.rs @@ -71,7 +71,7 @@ impl Command for StorImport { })?; } // dbg!(db.clone()); - Ok(Value::custom_value(db, span).into_pipeline_data()) + Ok(Value::custom(db, span).into_pipeline_data()) } } diff --git a/crates/nu-command/src/stor/insert.rs b/crates/nu-command/src/stor/insert.rs index 51cc971590..1b9f377531 100644 --- a/crates/nu-command/src/stor/insert.rs +++ b/crates/nu-command/src/stor/insert.rs @@ -131,7 +131,7 @@ impl Command for StorInsert { }; } // dbg!(db.clone()); - Ok(Value::custom_value(db, span).into_pipeline_data()) + Ok(Value::custom(db, span).into_pipeline_data()) } } diff --git a/crates/nu-command/src/stor/reset.rs b/crates/nu-command/src/stor/reset.rs index 9dfc33e20d..c1cb3b6b78 100644 --- a/crates/nu-command/src/stor/reset.rs +++ b/crates/nu-command/src/stor/reset.rs @@ -55,7 +55,7 @@ impl Command for StorReset { })?; } // dbg!(db.clone()); - Ok(Value::custom_value(db, span).into_pipeline_data()) + Ok(Value::custom(db, span).into_pipeline_data()) } } diff --git a/crates/nu-command/src/stor/update.rs b/crates/nu-command/src/stor/update.rs index ae63079d9c..dd49a36c47 100644 --- a/crates/nu-command/src/stor/update.rs +++ b/crates/nu-command/src/stor/update.rs @@ -143,7 +143,7 @@ impl Command for StorUpdate { }; } // dbg!(db.clone()); - Ok(Value::custom_value(db, span).into_pipeline_data()) + Ok(Value::custom(db, span).into_pipeline_data()) } } diff --git a/crates/nu-command/src/viewers/table.rs b/crates/nu-command/src/viewers/table.rs index fdcd1af01a..4b97813906 100644 --- a/crates/nu-command/src/viewers/table.rs +++ b/crates/nu-command/src/viewers/table.rs @@ -403,7 +403,7 @@ fn handle_table_command( // instead of stdout. Err(*error) } - PipelineData::Value(Value::CustomValue { val, .. }, ..) => { + PipelineData::Value(Value::Custom { val, .. }, ..) => { let base_pipeline = val.to_base_value(span)?.into_pipeline_data(); Table.run(input.engine_state, input.stack, input.call, base_pipeline) } diff --git a/crates/nu-plugin-test-support/tests/custom_value/mod.rs b/crates/nu-plugin-test-support/tests/custom_value/mod.rs index 12ee695b68..735a2daa9e 100644 --- a/crates/nu-plugin-test-support/tests/custom_value/mod.rs +++ b/crates/nu-plugin-test-support/tests/custom_value/mod.rs @@ -13,7 +13,7 @@ struct CustomU32(u32); impl CustomU32 { pub fn into_value(self, span: Span) -> Value { - Value::custom_value(Box::new(self), span) + Value::custom(Box::new(self), span) } } diff --git a/crates/nu-plugin/src/plugin/interface/engine/tests.rs b/crates/nu-plugin/src/plugin/interface/engine/tests.rs index fcb0a9ac5b..1ebe2491f7 100644 --- a/crates/nu-plugin/src/plugin/interface/engine/tests.rs +++ b/crates/nu-plugin/src/plugin/interface/engine/tests.rs @@ -609,7 +609,7 @@ fn manager_prepare_pipeline_data_embeds_deserialization_errors_in_streams() -> R let span = Span::new(20, 30); let data = manager.prepare_pipeline_data( - [Value::custom_value(Box::new(invalid_custom_value), span)].into_pipeline_data(None), + [Value::custom(Box::new(invalid_custom_value), span)].into_pipeline_data(None), )?; let value = data @@ -1147,7 +1147,7 @@ enum CantSerialize { #[typetag::serde] impl CustomValue for CantSerialize { fn clone_value(&self, span: Span) -> Value { - Value::custom_value(Box::new(self.clone()), span) + Value::custom(Box::new(self.clone()), span) } fn type_name(&self) -> String { @@ -1170,11 +1170,7 @@ fn interface_prepare_pipeline_data_embeds_serialization_errors_in_streams() -> R let span = Span::new(40, 60); let data = interface.prepare_pipeline_data( - [Value::custom_value( - Box::new(CantSerialize::BadVariant), - span, - )] - .into_pipeline_data(None), + [Value::custom(Box::new(CantSerialize::BadVariant), span)].into_pipeline_data(None), )?; let value = data diff --git a/crates/nu-plugin/src/protocol/plugin_custom_value.rs b/crates/nu-plugin/src/protocol/plugin_custom_value.rs index 445c9bd578..bd10c03029 100644 --- a/crates/nu-plugin/src/protocol/plugin_custom_value.rs +++ b/crates/nu-plugin/src/protocol/plugin_custom_value.rs @@ -53,7 +53,7 @@ fn is_false(b: &bool) -> bool { #[typetag::serde] impl CustomValue for PluginCustomValue { fn clone_value(&self, span: Span) -> Value { - Value::custom_value(Box::new(self.clone()), span) + Value::custom(Box::new(self.clone()), span) } fn type_name(&self) -> String { @@ -241,12 +241,12 @@ impl PluginCustomValue { let span = value.span(); match value { // Set source on custom value - Value::CustomValue { ref val, .. } => { + Value::Custom { ref val, .. } => { if let Some(custom_value) = val.as_any().downcast_ref::() { // Since there's no `as_mut_any()`, we have to copy the whole thing let mut custom_value = custom_value.clone(); custom_value.source = Some(source.clone()); - *value = Value::custom_value(Box::new(custom_value), span); + *value = Value::custom(Box::new(custom_value), span); } Ok(()) } @@ -272,7 +272,7 @@ impl PluginCustomValue { let span = value.span(); match value { // Set source on custom value - Value::CustomValue { val, .. } => { + Value::Custom { val, .. } => { if let Some(custom_value) = val.as_any().downcast_ref::() { if custom_value .source @@ -320,13 +320,13 @@ impl PluginCustomValue { value.recurse_mut(&mut |value| { let span = value.span(); match value { - Value::CustomValue { ref val, .. } => { + Value::Custom { ref val, .. } => { if val.as_any().downcast_ref::().is_some() { // Already a PluginCustomValue Ok(()) } else { let serialized = Self::serialize_from_custom_value(&**val, span)?; - *value = Value::custom_value(Box::new(serialized), span); + *value = Value::custom(Box::new(serialized), span); Ok(()) } } @@ -346,10 +346,10 @@ impl PluginCustomValue { value.recurse_mut(&mut |value| { let span = value.span(); match value { - Value::CustomValue { ref val, .. } => { + Value::Custom { ref val, .. } => { if let Some(val) = val.as_any().downcast_ref::() { let deserialized = val.deserialize_to_custom_value(span)?; - *value = Value::custom_value(deserialized, span); + *value = Value::custom(deserialized, span); Ok(()) } else { // Already not a PluginCustomValue @@ -371,7 +371,7 @@ impl PluginCustomValue { value.recurse_mut(&mut |value| { let span = value.span(); match value { - Value::CustomValue { ref val, .. } => { + Value::Custom { ref val, .. } => { *value = val.to_base_value(span)?; Ok(()) } diff --git a/crates/nu-plugin/src/protocol/plugin_custom_value/tests.rs b/crates/nu-plugin/src/protocol/plugin_custom_value/tests.rs index 5ba533ad77..aee87e0c2a 100644 --- a/crates/nu-plugin/src/protocol/plugin_custom_value/tests.rs +++ b/crates/nu-plugin/src/protocol/plugin_custom_value/tests.rs @@ -231,12 +231,12 @@ fn add_source_nested_closure() -> Result<(), ShellError> { #[test] fn verify_source_error_message() -> Result<(), ShellError> { let span = Span::new(5, 7); - let mut ok_val = Value::custom_value(Box::new(test_plugin_custom_value_with_source()), span); - let mut native_val = Value::custom_value(Box::new(TestCustomValue(32)), span); + let mut ok_val = Value::custom(Box::new(test_plugin_custom_value_with_source()), span); + let mut native_val = Value::custom(Box::new(TestCustomValue(32)), span); let mut foreign_val = { let mut val = test_plugin_custom_value(); val.source = Some(Arc::new(PluginSource::new_fake("other"))); - Value::custom_value(Box::new(val), span) + Value::custom(Box::new(val), span) }; let source = PluginSource::new_fake("test"); @@ -407,7 +407,7 @@ fn verify_source_nested_closure() -> Result<(), ShellError> { #[test] fn serialize_in_root() -> Result<(), ShellError> { let span = Span::new(4, 10); - let mut val = Value::custom_value(Box::new(expected_test_custom_value()), span); + let mut val = Value::custom(Box::new(expected_test_custom_value()), span); PluginCustomValue::serialize_custom_values_in(&mut val)?; assert_eq!(span, val.span()); @@ -520,7 +520,7 @@ fn serialize_in_closure() -> Result<(), ShellError> { #[test] fn deserialize_in_root() -> Result<(), ShellError> { let span = Span::new(4, 10); - let mut val = Value::custom_value(Box::new(test_plugin_custom_value()), span); + let mut val = Value::custom(Box::new(test_plugin_custom_value()), span); PluginCustomValue::deserialize_custom_values_in(&mut val)?; assert_eq!(span, val.span()); diff --git a/crates/nu-plugin/src/protocol/test_util.rs b/crates/nu-plugin/src/protocol/test_util.rs index 293326538e..338177fb2c 100644 --- a/crates/nu-plugin/src/protocol/test_util.rs +++ b/crates/nu-plugin/src/protocol/test_util.rs @@ -9,7 +9,7 @@ pub(crate) struct TestCustomValue(pub i32); #[typetag::serde] impl CustomValue for TestCustomValue { fn clone_value(&self, span: Span) -> Value { - Value::custom_value(Box::new(self.clone()), span) + Value::custom(Box::new(self.clone()), span) } fn type_name(&self) -> String { diff --git a/crates/nu-plugin/src/serializers/tests.rs b/crates/nu-plugin/src/serializers/tests.rs index 505c8fe915..dc134a9bdf 100644 --- a/crates/nu-plugin/src/serializers/tests.rs +++ b/crates/nu-plugin/src/serializers/tests.rs @@ -320,7 +320,7 @@ macro_rules! generate_tests { let data = vec![1, 2, 3, 4, 5]; let span = Span::new(2, 30); - let value = Value::custom_value( + let value = Value::custom( Box::new(PluginCustomValue::new( name.into(), data.clone(), diff --git a/crates/nu-protocol/src/value/mod.rs b/crates/nu-protocol/src/value/mod.rs index 7ba0762bee..473221a721 100644 --- a/crates/nu-protocol/src/value/mod.rs +++ b/crates/nu-protocol/src/value/mod.rs @@ -163,7 +163,7 @@ pub enum Value { #[serde(rename = "span")] internal_span: Span, }, - CustomValue { + Custom { val: Box, // note: spans are being refactored out of Value // please use .span() instead of matching this span value @@ -252,7 +252,7 @@ impl Clone for Value { val: val.clone(), internal_span: *internal_span, }, - Value::CustomValue { val, internal_span } => val.clone_value(*internal_span), + Value::Custom { val, internal_span } => val.clone_value(*internal_span), } } } @@ -698,7 +698,7 @@ impl Value { /// Returns a reference to the inner [`CustomValue`] trait object or an error if this `Value` is not a custom value pub fn as_custom_value(&self) -> Result<&dyn CustomValue, ShellError> { - if let Value::CustomValue { val, .. } = self { + if let Value::Custom { val, .. } = self { Ok(val.as_ref()) } else { self.cant_convert_to("custom value") @@ -707,7 +707,7 @@ impl Value { /// Unwraps the inner [`CustomValue`] trait object or returns an error if this `Value` is not a custom value pub fn into_custom_value(self) -> Result, ShellError> { - if let Value::CustomValue { val, .. } = self { + if let Value::Custom { val, .. } = self { Ok(val) } else { self.cant_convert_to("custom value") @@ -751,7 +751,7 @@ impl Value { | Value::Nothing { internal_span, .. } | Value::Binary { internal_span, .. } | Value::CellPath { internal_span, .. } - | Value::CustomValue { internal_span, .. } + | Value::Custom { internal_span, .. } | Value::LazyRecord { internal_span, .. } | Value::Error { internal_span, .. } => *internal_span, } @@ -777,7 +777,7 @@ impl Value { | Value::Nothing { internal_span, .. } | Value::Binary { internal_span, .. } | Value::CellPath { internal_span, .. } - | Value::CustomValue { internal_span, .. } => *internal_span = new_span, + | Value::Custom { internal_span, .. } => *internal_span = new_span, Value::Error { .. } => (), } } @@ -838,7 +838,7 @@ impl Value { Value::Error { .. } => Type::Error, Value::Binary { .. } => Type::Binary, Value::CellPath { .. } => Type::CellPath, - Value::CustomValue { val, .. } => Type::Custom(val.type_name()), + Value::Custom { val, .. } => Type::Custom(val.type_name()), } } @@ -956,7 +956,7 @@ impl Value { Value::CellPath { val, .. } => val.to_string(), // If we fail to collapse the custom value, just print <{type_name}> - failure is not // that critical here - Value::CustomValue { val, .. } => val + Value::Custom { val, .. } => val .to_base_value(span) .map(|val| val.to_expanded_string(separator, config)) .unwrap_or_else(|_| format!("<{}>", val.type_name())), @@ -1118,7 +1118,7 @@ impl Value { }); } } - Value::CustomValue { ref val, .. } => { + Value::Custom { ref val, .. } => { current = match val.follow_path_int(current.span(), *count, *origin_span) { Ok(val) => val, @@ -1262,7 +1262,7 @@ impl Value { current = Value::list(list, span); } - Value::CustomValue { ref val, .. } => { + Value::Custom { ref val, .. } => { current = match val.follow_path_string( current.span(), column_name.clone(), @@ -1890,7 +1890,7 @@ impl Value { | Value::Binary { .. } | Value::CellPath { .. } => Ok(()), // These could potentially contain values, but we expect the closure to handle them - Value::LazyRecord { .. } | Value::CustomValue { .. } => Ok(()), + Value::LazyRecord { .. } | Value::Custom { .. } => Ok(()), } } @@ -2051,8 +2051,8 @@ impl Value { } } - pub fn custom_value(val: Box, span: Span) -> Value { - Value::CustomValue { + pub fn custom(val: Box, span: Span) -> Value { + Value::Custom { val, internal_span: span, } @@ -2164,7 +2164,7 @@ impl Value { /// Note: Only use this for test data, *not* live data, as it will point into unknown source /// when used in errors. pub fn test_custom_value(val: Box) -> Value { - Value::custom_value(val, Span::test_data()) + Value::custom(val, Span::test_data()) } /// Note: Only use this for test data, *not* live data, as it will point into unknown source @@ -2257,7 +2257,7 @@ impl PartialOrd for Value { Value::Error { .. } => Some(Ordering::Less), Value::Binary { .. } => Some(Ordering::Less), Value::CellPath { .. } => Some(Ordering::Less), - Value::CustomValue { .. } => Some(Ordering::Less), + Value::Custom { .. } => Some(Ordering::Less), }, (Value::Int { val: lhs, .. }, rhs) => match rhs { Value::Bool { .. } => Some(Ordering::Greater), @@ -2278,7 +2278,7 @@ impl PartialOrd for Value { Value::Error { .. } => Some(Ordering::Less), Value::Binary { .. } => Some(Ordering::Less), Value::CellPath { .. } => Some(Ordering::Less), - Value::CustomValue { .. } => Some(Ordering::Less), + Value::Custom { .. } => Some(Ordering::Less), }, (Value::Float { val: lhs, .. }, rhs) => match rhs { Value::Bool { .. } => Some(Ordering::Greater), @@ -2299,7 +2299,7 @@ impl PartialOrd for Value { Value::Error { .. } => Some(Ordering::Less), Value::Binary { .. } => Some(Ordering::Less), Value::CellPath { .. } => Some(Ordering::Less), - Value::CustomValue { .. } => Some(Ordering::Less), + Value::Custom { .. } => Some(Ordering::Less), }, (Value::Filesize { val: lhs, .. }, rhs) => match rhs { Value::Bool { .. } => Some(Ordering::Greater), @@ -2320,7 +2320,7 @@ impl PartialOrd for Value { Value::Error { .. } => Some(Ordering::Less), Value::Binary { .. } => Some(Ordering::Less), Value::CellPath { .. } => Some(Ordering::Less), - Value::CustomValue { .. } => Some(Ordering::Less), + Value::Custom { .. } => Some(Ordering::Less), }, (Value::Duration { val: lhs, .. }, rhs) => match rhs { Value::Bool { .. } => Some(Ordering::Greater), @@ -2341,7 +2341,7 @@ impl PartialOrd for Value { Value::Error { .. } => Some(Ordering::Less), Value::Binary { .. } => Some(Ordering::Less), Value::CellPath { .. } => Some(Ordering::Less), - Value::CustomValue { .. } => Some(Ordering::Less), + Value::Custom { .. } => Some(Ordering::Less), }, (Value::Date { val: lhs, .. }, rhs) => match rhs { Value::Bool { .. } => Some(Ordering::Greater), @@ -2362,7 +2362,7 @@ impl PartialOrd for Value { Value::Error { .. } => Some(Ordering::Less), Value::Binary { .. } => Some(Ordering::Less), Value::CellPath { .. } => Some(Ordering::Less), - Value::CustomValue { .. } => Some(Ordering::Less), + Value::Custom { .. } => Some(Ordering::Less), }, (Value::Range { val: lhs, .. }, rhs) => match rhs { Value::Bool { .. } => Some(Ordering::Greater), @@ -2383,7 +2383,7 @@ impl PartialOrd for Value { Value::Error { .. } => Some(Ordering::Less), Value::Binary { .. } => Some(Ordering::Less), Value::CellPath { .. } => Some(Ordering::Less), - Value::CustomValue { .. } => Some(Ordering::Less), + Value::Custom { .. } => Some(Ordering::Less), }, (Value::String { val: lhs, .. }, rhs) => match rhs { Value::Bool { .. } => Some(Ordering::Greater), @@ -2404,7 +2404,7 @@ impl PartialOrd for Value { Value::Error { .. } => Some(Ordering::Less), Value::Binary { .. } => Some(Ordering::Less), Value::CellPath { .. } => Some(Ordering::Less), - Value::CustomValue { .. } => Some(Ordering::Less), + Value::Custom { .. } => Some(Ordering::Less), }, (Value::Glob { val: lhs, .. }, rhs) => match rhs { Value::Bool { .. } => Some(Ordering::Greater), @@ -2425,7 +2425,7 @@ impl PartialOrd for Value { Value::Error { .. } => Some(Ordering::Less), Value::Binary { .. } => Some(Ordering::Less), Value::CellPath { .. } => Some(Ordering::Less), - Value::CustomValue { .. } => Some(Ordering::Less), + Value::Custom { .. } => Some(Ordering::Less), }, (Value::Record { val: lhs, .. }, rhs) => match rhs { Value::Bool { .. } => Some(Ordering::Greater), @@ -2465,7 +2465,7 @@ impl PartialOrd for Value { Value::Error { .. } => Some(Ordering::Less), Value::Binary { .. } => Some(Ordering::Less), Value::CellPath { .. } => Some(Ordering::Less), - Value::CustomValue { .. } => Some(Ordering::Less), + Value::Custom { .. } => Some(Ordering::Less), }, (Value::List { vals: lhs, .. }, rhs) => match rhs { Value::Bool { .. } => Some(Ordering::Greater), @@ -2486,7 +2486,7 @@ impl PartialOrd for Value { Value::Error { .. } => Some(Ordering::Less), Value::Binary { .. } => Some(Ordering::Less), Value::CellPath { .. } => Some(Ordering::Less), - Value::CustomValue { .. } => Some(Ordering::Less), + Value::Custom { .. } => Some(Ordering::Less), }, (Value::Block { val: lhs, .. }, rhs) => match rhs { Value::Bool { .. } => Some(Ordering::Greater), @@ -2507,7 +2507,7 @@ impl PartialOrd for Value { Value::Error { .. } => Some(Ordering::Less), Value::Binary { .. } => Some(Ordering::Less), Value::CellPath { .. } => Some(Ordering::Less), - Value::CustomValue { .. } => Some(Ordering::Less), + Value::Custom { .. } => Some(Ordering::Less), }, (Value::Closure { val: lhs, .. }, rhs) => match rhs { Value::Bool { .. } => Some(Ordering::Greater), @@ -2528,7 +2528,7 @@ impl PartialOrd for Value { Value::Error { .. } => Some(Ordering::Less), Value::Binary { .. } => Some(Ordering::Less), Value::CellPath { .. } => Some(Ordering::Less), - Value::CustomValue { .. } => Some(Ordering::Less), + Value::Custom { .. } => Some(Ordering::Less), }, (Value::Nothing { .. }, rhs) => match rhs { Value::Bool { .. } => Some(Ordering::Greater), @@ -2549,7 +2549,7 @@ impl PartialOrd for Value { Value::Error { .. } => Some(Ordering::Less), Value::Binary { .. } => Some(Ordering::Less), Value::CellPath { .. } => Some(Ordering::Less), - Value::CustomValue { .. } => Some(Ordering::Less), + Value::Custom { .. } => Some(Ordering::Less), }, (Value::Error { .. }, rhs) => match rhs { Value::Bool { .. } => Some(Ordering::Greater), @@ -2570,7 +2570,7 @@ impl PartialOrd for Value { Value::Error { .. } => Some(Ordering::Equal), Value::Binary { .. } => Some(Ordering::Less), Value::CellPath { .. } => Some(Ordering::Less), - Value::CustomValue { .. } => Some(Ordering::Less), + Value::Custom { .. } => Some(Ordering::Less), }, (Value::Binary { val: lhs, .. }, rhs) => match rhs { Value::Bool { .. } => Some(Ordering::Greater), @@ -2591,7 +2591,7 @@ impl PartialOrd for Value { Value::Error { .. } => Some(Ordering::Greater), Value::Binary { val: rhs, .. } => lhs.partial_cmp(rhs), Value::CellPath { .. } => Some(Ordering::Less), - Value::CustomValue { .. } => Some(Ordering::Less), + Value::Custom { .. } => Some(Ordering::Less), }, (Value::CellPath { val: lhs, .. }, rhs) => match rhs { Value::Bool { .. } => Some(Ordering::Greater), @@ -2612,9 +2612,9 @@ impl PartialOrd for Value { Value::Error { .. } => Some(Ordering::Greater), Value::Binary { .. } => Some(Ordering::Greater), Value::CellPath { val: rhs, .. } => lhs.partial_cmp(rhs), - Value::CustomValue { .. } => Some(Ordering::Less), + Value::Custom { .. } => Some(Ordering::Less), }, - (Value::CustomValue { val: lhs, .. }, rhs) => lhs.partial_cmp(rhs), + (Value::Custom { val: lhs, .. }, rhs) => lhs.partial_cmp(rhs), (Value::LazyRecord { val, .. }, rhs) => { if let Ok(val) = val.collect() { val.partial_cmp(rhs) @@ -2689,7 +2689,7 @@ impl Value { } } - (Value::CustomValue { val: lhs, .. }, rhs) => { + (Value::Custom { val: lhs, .. }, rhs) => { lhs.operation(self.span(), Operator::Math(Math::Plus), op, rhs) } @@ -2729,7 +2729,7 @@ impl Value { val.extend(rhs); Ok(Value::binary(val, span)) } - (Value::CustomValue { val: lhs, .. }, rhs) => { + (Value::Custom { val: lhs, .. }, rhs) => { lhs.operation(self.span(), Operator::Math(Math::Append), op, rhs) } _ => Err(ShellError::OperatorMismatch { @@ -2806,7 +2806,7 @@ impl Value { } } - (Value::CustomValue { val: lhs, .. }, rhs) => { + (Value::Custom { val: lhs, .. }, rhs) => { lhs.operation(self.span(), Operator::Math(Math::Minus), op, rhs) } @@ -2862,7 +2862,7 @@ impl Value { (Value::Float { val: lhs, .. }, Value::Duration { val: rhs, .. }) => { Ok(Value::duration((*lhs * *rhs as f64) as i64, span)) } - (Value::CustomValue { val: lhs, .. }, rhs) => { + (Value::Custom { val: lhs, .. }, rhs) => { lhs.operation(self.span(), Operator::Math(Math::Multiply), op, rhs) } _ => Err(ShellError::OperatorMismatch { @@ -2965,7 +2965,7 @@ impl Value { Err(ShellError::DivisionByZero { span: op }) } } - (Value::CustomValue { val: lhs, .. }, rhs) => { + (Value::Custom { val: lhs, .. }, rhs) => { lhs.operation(self.span(), Operator::Math(Math::Divide), op, rhs) } @@ -3101,7 +3101,7 @@ impl Value { Err(ShellError::DivisionByZero { span: op }) } } - (Value::CustomValue { val: lhs, .. }, rhs) => { + (Value::Custom { val: lhs, .. }, rhs) => { lhs.operation(self.span(), Operator::Math(Math::Divide), op, rhs) } @@ -3116,7 +3116,7 @@ impl Value { } pub fn lt(&self, op: Span, rhs: &Value, span: Span) -> Result { - if let (Value::CustomValue { val: lhs, .. }, rhs) = (self, rhs) { + if let (Value::Custom { val: lhs, .. }, rhs) = (self, rhs) { return lhs.operation( self.span(), Operator::Comparison(Comparison::LessThan), @@ -3156,7 +3156,7 @@ impl Value { } pub fn lte(&self, op: Span, rhs: &Value, span: Span) -> Result { - if let (Value::CustomValue { val: lhs, .. }, rhs) = (self, rhs) { + if let (Value::Custom { val: lhs, .. }, rhs) = (self, rhs) { return lhs.operation( self.span(), Operator::Comparison(Comparison::LessThanOrEqual), @@ -3194,7 +3194,7 @@ impl Value { } pub fn gt(&self, op: Span, rhs: &Value, span: Span) -> Result { - if let (Value::CustomValue { val: lhs, .. }, rhs) = (self, rhs) { + if let (Value::Custom { val: lhs, .. }, rhs) = (self, rhs) { return lhs.operation( self.span(), Operator::Comparison(Comparison::GreaterThan), @@ -3232,7 +3232,7 @@ impl Value { } pub fn gte(&self, op: Span, rhs: &Value, span: Span) -> Result { - if let (Value::CustomValue { val: lhs, .. }, rhs) = (self, rhs) { + if let (Value::Custom { val: lhs, .. }, rhs) = (self, rhs) { return lhs.operation( self.span(), Operator::Comparison(Comparison::GreaterThanOrEqual), @@ -3274,7 +3274,7 @@ impl Value { } pub fn eq(&self, op: Span, rhs: &Value, span: Span) -> Result { - if let (Value::CustomValue { val: lhs, .. }, rhs) = (self, rhs) { + if let (Value::Custom { val: lhs, .. }, rhs) = (self, rhs) { return lhs.operation( self.span(), Operator::Comparison(Comparison::Equal), @@ -3302,7 +3302,7 @@ impl Value { } pub fn ne(&self, op: Span, rhs: &Value, span: Span) -> Result { - if let (Value::CustomValue { val: lhs, .. }, rhs) = (self, rhs) { + if let (Value::Custom { val: lhs, .. }, rhs) = (self, rhs) { return lhs.operation( self.span(), Operator::Comparison(Comparison::NotEqual), @@ -3364,7 +3364,7 @@ impl Value { span, )) } - (Value::CustomValue { val: lhs, .. }, rhs) => { + (Value::Custom { val: lhs, .. }, rhs) => { lhs.operation(self.span(), Operator::Comparison(Comparison::In), op, rhs) } _ => Err(ShellError::OperatorMismatch { @@ -3412,7 +3412,7 @@ impl Value { span, )) } - (Value::CustomValue { val: lhs, .. }, rhs) => lhs.operation( + (Value::Custom { val: lhs, .. }, rhs) => lhs.operation( self.span(), Operator::Comparison(Comparison::NotIn), op, @@ -3476,7 +3476,7 @@ impl Value { span, )) } - (Value::CustomValue { val: lhs, .. }, rhs) => lhs.operation( + (Value::Custom { val: lhs, .. }, rhs) => lhs.operation( span, if invert { Operator::Comparison(Comparison::NotRegexMatch) @@ -3501,7 +3501,7 @@ impl Value { (Value::String { val: lhs, .. }, Value::String { val: rhs, .. }) => { Ok(Value::bool(lhs.starts_with(rhs), span)) } - (Value::CustomValue { val: lhs, .. }, rhs) => lhs.operation( + (Value::Custom { val: lhs, .. }, rhs) => lhs.operation( self.span(), Operator::Comparison(Comparison::StartsWith), op, @@ -3522,7 +3522,7 @@ impl Value { (Value::String { val: lhs, .. }, Value::String { val: rhs, .. }) => { Ok(Value::bool(lhs.ends_with(rhs), span)) } - (Value::CustomValue { val: lhs, .. }, rhs) => lhs.operation( + (Value::Custom { val: lhs, .. }, rhs) => lhs.operation( self.span(), Operator::Comparison(Comparison::EndsWith), op, @@ -3543,7 +3543,7 @@ impl Value { (Value::Int { val: lhs, .. }, Value::Int { val: rhs, .. }) => { Ok(Value::int(*lhs << rhs, span)) } - (Value::CustomValue { val: lhs, .. }, rhs) => { + (Value::Custom { val: lhs, .. }, rhs) => { lhs.operation(span, Operator::Bits(Bits::ShiftLeft), op, rhs) } _ => Err(ShellError::OperatorMismatch { @@ -3561,7 +3561,7 @@ impl Value { (Value::Int { val: lhs, .. }, Value::Int { val: rhs, .. }) => { Ok(Value::int(*lhs >> rhs, span)) } - (Value::CustomValue { val: lhs, .. }, rhs) => { + (Value::Custom { val: lhs, .. }, rhs) => { lhs.operation(span, Operator::Bits(Bits::ShiftRight), op, rhs) } _ => Err(ShellError::OperatorMismatch { @@ -3579,7 +3579,7 @@ impl Value { (Value::Int { val: lhs, .. }, Value::Int { val: rhs, .. }) => { Ok(Value::int(*lhs | rhs, span)) } - (Value::CustomValue { val: lhs, .. }, rhs) => { + (Value::Custom { val: lhs, .. }, rhs) => { lhs.operation(span, Operator::Bits(Bits::BitOr), op, rhs) } _ => Err(ShellError::OperatorMismatch { @@ -3597,7 +3597,7 @@ impl Value { (Value::Int { val: lhs, .. }, Value::Int { val: rhs, .. }) => { Ok(Value::int(*lhs ^ rhs, span)) } - (Value::CustomValue { val: lhs, .. }, rhs) => { + (Value::Custom { val: lhs, .. }, rhs) => { lhs.operation(span, Operator::Bits(Bits::BitXor), op, rhs) } _ => Err(ShellError::OperatorMismatch { @@ -3615,7 +3615,7 @@ impl Value { (Value::Int { val: lhs, .. }, Value::Int { val: rhs, .. }) => { Ok(Value::int(*lhs & rhs, span)) } - (Value::CustomValue { val: lhs, .. }, rhs) => { + (Value::Custom { val: lhs, .. }, rhs) => { lhs.operation(span, Operator::Bits(Bits::BitAnd), op, rhs) } _ => Err(ShellError::OperatorMismatch { @@ -3665,7 +3665,7 @@ impl Value { Err(ShellError::DivisionByZero { span: op }) } } - (Value::CustomValue { val: lhs, .. }, rhs) => { + (Value::Custom { val: lhs, .. }, rhs) => { lhs.operation(span, Operator::Math(Math::Modulo), op, rhs) } @@ -3684,7 +3684,7 @@ impl Value { (Value::Bool { val: lhs, .. }, Value::Bool { val: rhs, .. }) => { Ok(Value::bool(*lhs && *rhs, span)) } - (Value::CustomValue { val: lhs, .. }, rhs) => { + (Value::Custom { val: lhs, .. }, rhs) => { lhs.operation(span, Operator::Boolean(Boolean::And), op, rhs) } _ => Err(ShellError::OperatorMismatch { @@ -3702,7 +3702,7 @@ impl Value { (Value::Bool { val: lhs, .. }, Value::Bool { val: rhs, .. }) => { Ok(Value::bool(*lhs || *rhs, span)) } - (Value::CustomValue { val: lhs, .. }, rhs) => { + (Value::Custom { val: lhs, .. }, rhs) => { lhs.operation(span, Operator::Boolean(Boolean::Or), op, rhs) } _ => Err(ShellError::OperatorMismatch { @@ -3720,7 +3720,7 @@ impl Value { (Value::Bool { val: lhs, .. }, Value::Bool { val: rhs, .. }) => { Ok(Value::bool((*lhs && !*rhs) || (!*lhs && *rhs), span)) } - (Value::CustomValue { val: lhs, .. }, rhs) => { + (Value::Custom { val: lhs, .. }, rhs) => { lhs.operation(span, Operator::Boolean(Boolean::Xor), op, rhs) } _ => Err(ShellError::OperatorMismatch { @@ -3751,7 +3751,7 @@ impl Value { (Value::Float { val: lhs, .. }, Value::Float { val: rhs, .. }) => { Ok(Value::float(lhs.powf(*rhs), span)) } - (Value::CustomValue { val: lhs, .. }, rhs) => { + (Value::Custom { val: lhs, .. }, rhs) => { lhs.operation(span, Operator::Math(Math::Pow), op, rhs) } diff --git a/crates/nu_plugin_custom_values/src/cool_custom_value.rs b/crates/nu_plugin_custom_values/src/cool_custom_value.rs index 588ad84f1e..058e66da90 100644 --- a/crates/nu_plugin_custom_values/src/cool_custom_value.rs +++ b/crates/nu_plugin_custom_values/src/cool_custom_value.rs @@ -15,13 +15,13 @@ impl CoolCustomValue { } pub fn into_value(self, span: Span) -> Value { - Value::custom_value(Box::new(self), span) + Value::custom(Box::new(self), span) } pub fn try_from_value(value: &Value) -> Result { let span = value.span(); match value { - Value::CustomValue { val, .. } => { + Value::Custom { val, .. } => { if let Some(cool) = val.as_any().downcast_ref::() { Ok(cool.clone()) } else { @@ -46,7 +46,7 @@ impl CoolCustomValue { #[typetag::serde] impl CustomValue for CoolCustomValue { fn clone_value(&self, span: Span) -> Value { - Value::custom_value(Box::new(self.clone()), span) + Value::custom(Box::new(self.clone()), span) } fn type_name(&self) -> String { @@ -94,7 +94,7 @@ impl CustomValue for CoolCustomValue { } fn partial_cmp(&self, other: &Value) -> Option { - if let Value::CustomValue { val, .. } = other { + if let Value::Custom { val, .. } = other { val.as_any() .downcast_ref() .and_then(|other: &CoolCustomValue| PartialOrd::partial_cmp(self, other)) @@ -118,7 +118,7 @@ impl CustomValue for CoolCustomValue { .ok() .and_then(|c| c.as_any().downcast_ref::()) { - Ok(Value::custom_value( + Ok(Value::custom( Box::new(CoolCustomValue { cool: format!("{}{}", self.cool, right.cool), }), diff --git a/crates/nu_plugin_custom_values/src/drop_check.rs b/crates/nu_plugin_custom_values/src/drop_check.rs index b12f5e837c..4cb7f54bf9 100644 --- a/crates/nu_plugin_custom_values/src/drop_check.rs +++ b/crates/nu_plugin_custom_values/src/drop_check.rs @@ -16,7 +16,7 @@ impl DropCheckValue { } pub(crate) fn into_value(self, span: Span) -> Value { - Value::custom_value(Box::new(self), span) + Value::custom(Box::new(self), span) } pub(crate) fn notify(&self) { diff --git a/crates/nu_plugin_custom_values/src/second_custom_value.rs b/crates/nu_plugin_custom_values/src/second_custom_value.rs index a9c3bb7488..7a7647f521 100644 --- a/crates/nu_plugin_custom_values/src/second_custom_value.rs +++ b/crates/nu_plugin_custom_values/src/second_custom_value.rs @@ -16,13 +16,13 @@ impl SecondCustomValue { } pub fn into_value(self, span: Span) -> Value { - Value::custom_value(Box::new(self), span) + Value::custom(Box::new(self), span) } pub fn try_from_value(value: &Value) -> Result { let span = value.span(); match value { - Value::CustomValue { val, .. } => match val.as_any().downcast_ref::() { + Value::Custom { val, .. } => match val.as_any().downcast_ref::() { Some(value) => Ok(value.clone()), None => Err(ShellError::CantConvert { to_type: "cool".into(), @@ -44,7 +44,7 @@ impl SecondCustomValue { #[typetag::serde] impl CustomValue for SecondCustomValue { fn clone_value(&self, span: nu_protocol::Span) -> Value { - Value::custom_value(Box::new(self.clone()), span) + Value::custom(Box::new(self.clone()), span) } fn type_name(&self) -> String { @@ -62,7 +62,7 @@ impl CustomValue for SecondCustomValue { } fn partial_cmp(&self, other: &Value) -> Option { - if let Value::CustomValue { val, .. } = other { + if let Value::Custom { val, .. } = other { val.as_any() .downcast_ref() .and_then(|other: &SecondCustomValue| PartialOrd::partial_cmp(self, other))