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
This commit is contained in:
Stefan Holderbach 2024-03-27 22:10:56 +01:00 committed by GitHub
parent dfbbacfdf8
commit b19da158d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
48 changed files with 144 additions and 148 deletions

View file

@ -87,7 +87,7 @@ fn command(
let lazy = NuLazyFrame::new(false, df_sql); let lazy = NuLazyFrame::new(false, df_sql);
let eager = lazy.collect(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)) Ok(PipelineData::Value(value, None))
} }

View file

@ -55,7 +55,7 @@ impl Command for LazyCollect {
) -> Result<PipelineData, ShellError> { ) -> Result<PipelineData, ShellError> {
let lazy = NuLazyFrame::try_from_pipeline(input, call.head)?; let lazy = NuLazyFrame::try_from_pipeline(input, call.head)?;
let eager = lazy.collect(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)) Ok(PipelineData::Value(value, None))
} }

View file

@ -47,7 +47,7 @@ impl Command for ToLazyFrame {
let df = NuDataFrame::try_from_iter(input.into_iter(), maybe_schema)?; let df = NuDataFrame::try_from_iter(input.into_iter(), maybe_schema)?;
let lazy = NuLazyFrame::from_dataframe(df); 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)) Ok(PipelineData::Value(value, None))
} }

View file

@ -17,7 +17,7 @@ impl CustomValue for NuDataFrame {
from_lazy: false, from_lazy: false,
}; };
Value::custom_value(Box::new(cloned), span) Value::custom(Box::new(cloned), span)
} }
fn type_name(&self) -> String { fn type_name(&self) -> String {
@ -55,7 +55,7 @@ impl CustomValue for NuDataFrame {
fn partial_cmp(&self, other: &Value) -> Option<std::cmp::Ordering> { fn partial_cmp(&self, other: &Value) -> Option<std::cmp::Ordering> {
match other { match other {
Value::CustomValue { val, .. } => val Value::Custom { val, .. } => val
.as_any() .as_any()
.downcast_ref::<Self>() .downcast_ref::<Self>()
.and_then(|other| self.is_equal(other)), .and_then(|other| self.is_equal(other)),

View file

@ -116,15 +116,15 @@ impl NuDataFrame {
} }
pub fn dataframe_into_value(dataframe: DataFrame, span: Span) -> Value { 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 { pub fn into_value(self, span: Span) -> Value {
if self.from_lazy { if self.from_lazy {
let lazy = NuLazyFrame::from_dataframe(self); let lazy = NuLazyFrame::from_dataframe(self);
Value::custom_value(Box::new(lazy), span) Value::custom(Box::new(lazy), span)
} else { } else {
Value::custom_value(Box::new(self), span) Value::custom(Box::new(self), span)
} }
} }
@ -152,7 +152,7 @@ impl NuDataFrame {
for value in iter { for value in iter {
match value { match value {
Value::CustomValue { .. } => return Self::try_from_value(value), Value::Custom { .. } => return Self::try_from_value(value),
Value::List { vals, .. } => { Value::List { vals, .. } => {
let record = vals let record = vals
.into_iter() .into_iter()
@ -256,7 +256,7 @@ impl NuDataFrame {
pub fn get_df(value: Value) -> Result<Self, ShellError> { pub fn get_df(value: Value) -> Result<Self, ShellError> {
let span = value.span(); let span = value.span();
match value { match value {
Value::CustomValue { val, .. } => match val.as_any().downcast_ref::<Self>() { Value::Custom { val, .. } => match val.as_any().downcast_ref::<Self>() {
Some(df) => Ok(NuDataFrame { Some(df) => Ok(NuDataFrame {
df: df.df.clone(), df: df.df.clone(),
from_lazy: false, from_lazy: false,
@ -283,7 +283,7 @@ impl NuDataFrame {
} }
pub fn can_downcast(value: &Value) -> bool { pub fn can_downcast(value: &Value) -> bool {
if let Value::CustomValue { val, .. } = value { if let Value::Custom { val, .. } = value {
val.as_any().downcast_ref::<Self>().is_some() val.as_any().downcast_ref::<Self>().is_some()
} else { } else {
false false

View file

@ -20,7 +20,7 @@ impl NuDataFrame {
) -> Result<Value, ShellError> { ) -> Result<Value, ShellError> {
let rhs_span = right.span(); let rhs_span = right.span();
match right { match right {
Value::CustomValue { val: rhs, .. } => { Value::Custom { val: rhs, .. } => {
let rhs = rhs.as_any().downcast_ref::<NuDataFrame>().ok_or_else(|| { let rhs = rhs.as_any().downcast_ref::<NuDataFrame>().ok_or_else(|| {
ShellError::DowncastNotPossible { ShellError::DowncastNotPossible {
msg: "Unable to create dataframe".to_string(), msg: "Unable to create dataframe".to_string(),

View file

@ -19,7 +19,7 @@ impl CustomValue for NuExpression {
fn clone_value(&self, span: nu_protocol::Span) -> Value { fn clone_value(&self, span: nu_protocol::Span) -> Value {
let cloned = NuExpression(self.0.clone()); let cloned = NuExpression(self.0.clone());
Value::custom_value(Box::new(cloned), span) Value::custom(Box::new(cloned), span)
} }
fn type_name(&self) -> String { fn type_name(&self) -> String {
@ -54,7 +54,7 @@ fn compute_with_value(
) -> Result<Value, ShellError> { ) -> Result<Value, ShellError> {
let rhs_span = right.span(); let rhs_span = right.span();
match right { match right {
Value::CustomValue { val: rhs, .. } => { Value::Custom { val: rhs, .. } => {
let rhs = rhs.as_any().downcast_ref::<NuExpression>().ok_or_else(|| { let rhs = rhs.as_any().downcast_ref::<NuExpression>().ok_or_else(|| {
ShellError::DowncastNotPossible { ShellError::DowncastNotPossible {
msg: "Unable to create expression".into(), msg: "Unable to create expression".into(),

View file

@ -55,13 +55,13 @@ impl From<Expr> for NuExpression {
impl NuExpression { impl NuExpression {
pub fn into_value(self, span: Span) -> Value { 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<Self, ShellError> { pub fn try_from_value(value: Value) -> Result<Self, ShellError> {
let span = value.span(); let span = value.span();
match value { match value {
Value::CustomValue { val, .. } => match val.as_any().downcast_ref::<Self>() { Value::Custom { val, .. } => match val.as_any().downcast_ref::<Self>() {
Some(expr) => Ok(NuExpression(expr.0.clone())), Some(expr) => Ok(NuExpression(expr.0.clone())),
None => Err(ShellError::CantConvert { None => Err(ShellError::CantConvert {
to_type: "lazy expression".into(), to_type: "lazy expression".into(),
@ -90,7 +90,7 @@ impl NuExpression {
pub fn can_downcast(value: &Value) -> bool { pub fn can_downcast(value: &Value) -> bool {
match value { match value {
Value::CustomValue { val, .. } => val.as_any().downcast_ref::<Self>().is_some(), Value::Custom { val, .. } => val.as_any().downcast_ref::<Self>().is_some(),
Value::List { vals, .. } => vals.iter().all(Self::can_downcast), Value::List { vals, .. } => vals.iter().all(Self::can_downcast),
Value::String { .. } | Value::Int { .. } | Value::Bool { .. } | Value::Float { .. } => { Value::String { .. } | Value::Int { .. } | Value::Bool { .. } | Value::Float { .. } => {
true true
@ -144,7 +144,7 @@ impl ExtractedExpr {
fn extract_exprs(value: Value) -> Result<ExtractedExpr, ShellError> { fn extract_exprs(value: Value) -> Result<ExtractedExpr, ShellError> {
match value { match value {
Value::String { val, .. } => Ok(ExtractedExpr::Single(col(val.as_str()))), 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(NuExpression::into_polars)
.map(ExtractedExpr::Single), .map(ExtractedExpr::Single),
Value::List { vals, .. } => vals Value::List { vals, .. } => vals

View file

@ -18,7 +18,7 @@ impl CustomValue for NuLazyFrame {
schema: self.schema.clone(), schema: self.schema.clone(),
}; };
Value::custom_value(Box::new(cloned), span) Value::custom(Box::new(cloned), span)
} }
fn type_name(&self) -> String { fn type_name(&self) -> String {

View file

@ -90,9 +90,9 @@ impl NuLazyFrame {
pub fn into_value(self, span: Span) -> Result<Value, ShellError> { pub fn into_value(self, span: Span) -> Result<Value, ShellError> {
if self.from_eager { if self.from_eager {
let df = self.collect(span)?; let df = self.collect(span)?;
Ok(Value::custom_value(Box::new(df), span)) Ok(Value::custom(Box::new(df), span))
} else { } 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<Self, ShellError> { pub fn get_lazy_df(value: Value) -> Result<Self, ShellError> {
let span = value.span(); let span = value.span();
match value { match value {
Value::CustomValue { val, .. } => match val.as_any().downcast_ref::<Self>() { Value::Custom { val, .. } => match val.as_any().downcast_ref::<Self>() {
Some(expr) => Ok(Self { Some(expr) => Ok(Self {
lazy: expr.lazy.clone(), lazy: expr.lazy.clone(),
from_eager: false, from_eager: false,
@ -164,7 +164,7 @@ impl NuLazyFrame {
} }
pub fn can_downcast(value: &Value) -> bool { pub fn can_downcast(value: &Value) -> bool {
if let Value::CustomValue { val, .. } = value { if let Value::Custom { val, .. } = value {
val.as_any().downcast_ref::<Self>().is_some() val.as_any().downcast_ref::<Self>().is_some()
} else { } else {
false false

View file

@ -18,7 +18,7 @@ impl CustomValue for NuLazyGroupBy {
from_eager: self.from_eager, from_eager: self.from_eager,
}; };
Value::custom_value(Box::new(cloned), span) Value::custom(Box::new(cloned), span)
} }
fn type_name(&self) -> String { fn type_name(&self) -> String {

View file

@ -74,7 +74,7 @@ impl From<LazyGroupBy> for NuLazyGroupBy {
impl NuLazyGroupBy { impl NuLazyGroupBy {
pub fn into_value(self, span: Span) -> Value { 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 { pub fn into_polars(self) -> LazyGroupBy {
@ -84,7 +84,7 @@ impl NuLazyGroupBy {
pub fn try_from_value(value: Value) -> Result<Self, ShellError> { pub fn try_from_value(value: Value) -> Result<Self, ShellError> {
let span = value.span(); let span = value.span();
match value { match value {
Value::CustomValue { val, .. } => match val.as_any().downcast_ref::<NuLazyGroupBy>() { Value::Custom { val, .. } => match val.as_any().downcast_ref::<NuLazyGroupBy>() {
Some(group) => Ok(Self { Some(group) => Ok(Self {
group_by: group.group_by.clone(), group_by: group.group_by.clone(),
schema: group.schema.clone(), schema: group.schema.clone(),

View file

@ -14,7 +14,7 @@ impl CustomValue for NuWhen {
fn clone_value(&self, span: nu_protocol::Span) -> Value { fn clone_value(&self, span: nu_protocol::Span) -> Value {
let cloned = self.clone(); let cloned = self.clone();
Value::custom_value(Box::new(cloned), span) Value::custom(Box::new(cloned), span)
} }
fn type_name(&self) -> String { fn type_name(&self) -> String {

View file

@ -51,13 +51,13 @@ impl From<ChainedThen> for NuWhen {
impl NuWhen { impl NuWhen {
pub fn into_value(self, span: Span) -> Value { 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<Self, ShellError> { pub fn try_from_value(value: Value) -> Result<Self, ShellError> {
let span = value.span(); let span = value.span();
match value { match value {
Value::CustomValue { val, .. } => match val.as_any().downcast_ref::<Self>() { Value::Custom { val, .. } => match val.as_any().downcast_ref::<Self>() {
Some(expr) => Ok(expr.clone()), Some(expr) => Ok(expr.clone()),
None => Err(ShellError::CantConvert { None => Err(ShellError::CantConvert {
to_type: "when expression".into(), to_type: "when expression".into(),

View file

@ -281,7 +281,7 @@ fn describe_value(
options: Options, options: Options,
) -> Result<Value, ShellError> { ) -> Result<Value, ShellError> {
Ok(match value { Ok(match value {
Value::CustomValue { val, .. } => Value::record( Value::Custom { val, .. } => Value::record(
record!( record!(
"type" => Value::string("custom", head), "type" => Value::string("custom", head),
"subtype" => Value::string(val.type_name(), head), "subtype" => Value::string(val.type_name(), head),

View file

@ -274,7 +274,7 @@ impl<'a> std::fmt::Debug for DebuggableValue<'a> {
Value::CellPath { val, .. } => { Value::CellPath { val, .. } => {
write!(f, "CellPath({:?})", val.to_string()) write!(f, "CellPath({:?})", val.to_string())
} }
Value::CustomValue { val, .. } => { Value::Custom { val, .. } => {
write!(f, "CustomValue({:?})", val) write!(f, "CustomValue({:?})", val)
} }
Value::LazyRecord { val, .. } => { Value::LazyRecord { val, .. } => {

View file

@ -130,7 +130,7 @@ impl<'a> StyleComputer<'a> {
TextStyle::with_style(Left, s) TextStyle::with_style(Left, s)
} }
Value::Closure { .. } Value::Closure { .. }
| Value::CustomValue { .. } | Value::Custom { .. }
| Value::Error { .. } | Value::Error { .. }
| Value::LazyRecord { .. } => TextStyle::basic_left(), | Value::LazyRecord { .. } => TextStyle::basic_left(),
} }

View file

@ -226,7 +226,7 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
}, },
span, span,
), ),
Value::CustomValue { val, .. } => { Value::Custom { val, .. } => {
// Only custom values that have a base value that can be converted to string are // Only custom values that have a base value that can be converted to string are
// accepted. // accepted.
val.to_base_value(input.span()) val.to_base_value(input.span())

View file

@ -69,7 +69,7 @@ impl SQLiteDatabase {
pub fn try_from_value(value: Value) -> Result<Self, ShellError> { pub fn try_from_value(value: Value) -> Result<Self, ShellError> {
let span = value.span(); let span = value.span();
match value { match value {
Value::CustomValue { val, .. } => match val.as_any().downcast_ref::<Self>() { Value::Custom { val, .. } => match val.as_any().downcast_ref::<Self>() {
Some(db) => Ok(Self { Some(db) => Ok(Self {
path: db.path.clone(), path: db.path.clone(),
ctrlc: db.ctrlc.clone(), ctrlc: db.ctrlc.clone(),
@ -97,7 +97,7 @@ impl SQLiteDatabase {
pub fn into_value(self, span: Span) -> Value { pub fn into_value(self, span: Span) -> Value {
let db = Box::new(self); let db = Box::new(self);
Value::custom_value(db, span) Value::custom(db, span)
} }
pub fn query( pub fn query(
@ -357,7 +357,7 @@ impl CustomValue for SQLiteDatabase {
ctrlc: self.ctrlc.clone(), ctrlc: self.ctrlc.clone(),
}; };
Value::custom_value(Box::new(cloned), span) Value::custom(Box::new(cloned), span)
} }
fn type_name(&self) -> String { fn type_name(&self) -> String {

View file

@ -293,7 +293,7 @@ pub fn debug_string_without_formatting(value: &Value) -> String {
Value::CellPath { val, .. } => val.to_string(), Value::CellPath { val, .. } => val.to_string(),
// If we fail to collapse the custom value, just print <{type_name}> - failure is not // If we fail to collapse the custom value, just print <{type_name}> - failure is not
// that critical here // that critical here
Value::CustomValue { val, .. } => val Value::Custom { val, .. } => val
.to_base_value(value.span()) .to_base_value(value.span())
.map(|val| debug_string_without_formatting(&val)) .map(|val| debug_string_without_formatting(&val))
.unwrap_or_else(|_| format!("<{}>", val.type_name())), .unwrap_or_else(|_| format!("<{}>", val.type_name())),

View file

@ -94,7 +94,7 @@ fn getcol(
.into_pipeline_data(ctrlc) .into_pipeline_data(ctrlc)
.set_metadata(metadata)) .set_metadata(metadata))
} }
Value::CustomValue { val, .. } => { Value::Custom { val, .. } => {
// TODO: should we get CustomValue to expose columns in a more efficient way? // 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 // Would be nice to be able to get columns without generating the whole value
let input_as_base_value = val.to_base_value(span)?; let input_as_base_value = val.to_base_value(span)?;

View file

@ -531,7 +531,7 @@ fn value_should_be_printed(
| Value::Glob { .. } | Value::Glob { .. }
| Value::List { .. } | Value::List { .. }
| Value::CellPath { .. } | Value::CellPath { .. }
| Value::CustomValue { .. } => term_contains_value(term, &lower_value, span), | Value::Custom { .. } => term_contains_value(term, &lower_value, span),
Value::Record { val, .. } => { Value::Record { val, .. } => {
record_matches_term(val, columns_to_search, filter_config, term, span) record_matches_term(val, columns_to_search, filter_config, term, span)
} }

View file

@ -147,7 +147,7 @@ fn values(
.into_pipeline_data_with_metadata(metadata, ctrlc)), .into_pipeline_data_with_metadata(metadata, ctrlc)),
Err(err) => Err(err), Err(err) => Err(err),
}, },
Value::CustomValue { val, .. } => { Value::Custom { val, .. } => {
let input_as_base_value = val.to_base_value(span)?; let input_as_base_value = val.to_base_value(span)?;
match get_values(&[input_as_base_value], head, span) { match get_values(&[input_as_base_value], head, span) {
Ok(cols) => Ok(cols Ok(cols) => Ok(cols

View file

@ -115,7 +115,7 @@ fn to_string_tagged_value(
| Value::Int { .. } | Value::Int { .. }
| Value::Duration { .. } | Value::Duration { .. }
| Value::Binary { .. } | Value::Binary { .. }
| Value::CustomValue { .. } | Value::Custom { .. }
| Value::Filesize { .. } | Value::Filesize { .. }
| Value::CellPath { .. } | Value::CellPath { .. }
| Value::Float { .. } => Ok(v.clone().to_abbreviated_string(config)), | Value::Float { .. } => Ok(v.clone().to_abbreviated_string(config)),

View file

@ -139,7 +139,7 @@ pub fn value_to_json_value(v: &Value) -> Result<nu_json::Value, ShellError> {
let collected = val.collect()?; let collected = val.collect()?;
value_to_json_value(&collected)? value_to_json_value(&collected)?
} }
Value::CustomValue { val, .. } => { Value::Custom { val, .. } => {
let collected = val.to_base_value(span)?; let collected = val.to_base_value(span)?;
value_to_json_value(&collected)? value_to_json_value(&collected)?
} }

View file

@ -158,7 +158,7 @@ pub fn value_to_string(
msg_span: span, msg_span: span,
input_span: v.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(), msg: "custom values are currently not nuon-compatible".to_string(),
input: "value originates from here".into(), input: "value originates from here".into(),
msg_span: span, msg_span: span,

View file

@ -147,7 +147,7 @@ fn local_into_string(value: Value, separator: &str, config: &Config) -> String {
Value::CellPath { val, .. } => val.to_string(), Value::CellPath { val, .. } => val.to_string(),
// If we fail to collapse the custom value, just print <{type_name}> - failure is not // If we fail to collapse the custom value, just print <{type_name}> - failure is not
// that critical here // that critical here
Value::CustomValue { val, .. } => val Value::Custom { val, .. } => val
.to_base_value(span) .to_base_value(span)
.map(|val| local_into_string(val, separator, config)) .map(|val| local_into_string(val, separator, config))
.unwrap_or_else(|_| format!("<{}>", val.type_name())), .unwrap_or_else(|_| format!("<{}>", val.type_name())),

View file

@ -93,7 +93,7 @@ fn helper(engine_state: &EngineState, v: &Value) -> Result<toml::Value, ShellErr
}) })
.collect::<Result<Vec<toml::Value>, ShellError>>()?, .collect::<Result<Vec<toml::Value>, ShellError>>()?,
), ),
Value::CustomValue { .. } => toml::Value::String("<Custom Value>".to_string()), Value::Custom { .. } => toml::Value::String("<Custom Value>".to_string()),
}) })
} }

View file

@ -95,7 +95,7 @@ pub fn value_to_yaml_value(v: &Value) -> Result<serde_yaml::Value, ShellError> {
}) })
.collect::<Result<Vec<serde_yaml::Value>, ShellError>>()?, .collect::<Result<Vec<serde_yaml::Value>, ShellError>>()?,
), ),
Value::CustomValue { .. } => serde_yaml::Value::Null, Value::Custom { .. } => serde_yaml::Value::Null,
}) })
} }

View file

@ -30,7 +30,7 @@ pub fn sort_value(
Ok(Value::list(vals, span)) Ok(Value::list(vals, span))
} }
Value::CustomValue { val, .. } => { Value::Custom { val, .. } => {
let base_val = val.to_base_value(span)?; let base_val = val.to_base_value(span)?;
sort_value(&base_val, sort_columns, ascending, insensitive, natural) sort_value(&base_val, sort_columns, ascending, insensitive, natural)
} }

View file

@ -58,7 +58,7 @@ impl Command for StorCreate {
process(table_name, span, &db, columns)?; process(table_name, span, &db, columns)?;
// dbg!(db.clone()); // dbg!(db.clone());
Ok(Value::custom_value(db, span).into_pipeline_data()) Ok(Value::custom(db, span).into_pipeline_data())
} }
} }

View file

@ -117,7 +117,7 @@ impl Command for StorDelete {
} }
} }
// dbg!(db.clone()); // dbg!(db.clone());
Ok(Value::custom_value(db, span).into_pipeline_data()) Ok(Value::custom(db, span).into_pipeline_data())
} }
} }

View file

@ -73,7 +73,7 @@ impl Command for StorExport {
})?; })?;
} }
// dbg!(db.clone()); // dbg!(db.clone());
Ok(Value::custom_value(db, span).into_pipeline_data()) Ok(Value::custom(db, span).into_pipeline_data())
} }
} }

View file

@ -71,7 +71,7 @@ impl Command for StorImport {
})?; })?;
} }
// dbg!(db.clone()); // dbg!(db.clone());
Ok(Value::custom_value(db, span).into_pipeline_data()) Ok(Value::custom(db, span).into_pipeline_data())
} }
} }

View file

@ -131,7 +131,7 @@ impl Command for StorInsert {
}; };
} }
// dbg!(db.clone()); // dbg!(db.clone());
Ok(Value::custom_value(db, span).into_pipeline_data()) Ok(Value::custom(db, span).into_pipeline_data())
} }
} }

View file

@ -55,7 +55,7 @@ impl Command for StorReset {
})?; })?;
} }
// dbg!(db.clone()); // dbg!(db.clone());
Ok(Value::custom_value(db, span).into_pipeline_data()) Ok(Value::custom(db, span).into_pipeline_data())
} }
} }

View file

@ -143,7 +143,7 @@ impl Command for StorUpdate {
}; };
} }
// dbg!(db.clone()); // dbg!(db.clone());
Ok(Value::custom_value(db, span).into_pipeline_data()) Ok(Value::custom(db, span).into_pipeline_data())
} }
} }

View file

@ -403,7 +403,7 @@ fn handle_table_command(
// instead of stdout. // instead of stdout.
Err(*error) Err(*error)
} }
PipelineData::Value(Value::CustomValue { val, .. }, ..) => { PipelineData::Value(Value::Custom { val, .. }, ..) => {
let base_pipeline = val.to_base_value(span)?.into_pipeline_data(); let base_pipeline = val.to_base_value(span)?.into_pipeline_data();
Table.run(input.engine_state, input.stack, input.call, base_pipeline) Table.run(input.engine_state, input.stack, input.call, base_pipeline)
} }

View file

@ -13,7 +13,7 @@ struct CustomU32(u32);
impl CustomU32 { impl CustomU32 {
pub fn into_value(self, span: Span) -> Value { pub fn into_value(self, span: Span) -> Value {
Value::custom_value(Box::new(self), span) Value::custom(Box::new(self), span)
} }
} }

View file

@ -609,7 +609,7 @@ fn manager_prepare_pipeline_data_embeds_deserialization_errors_in_streams() -> R
let span = Span::new(20, 30); let span = Span::new(20, 30);
let data = manager.prepare_pipeline_data( 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 let value = data
@ -1147,7 +1147,7 @@ enum CantSerialize {
#[typetag::serde] #[typetag::serde]
impl CustomValue for CantSerialize { impl CustomValue for CantSerialize {
fn clone_value(&self, span: Span) -> Value { 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 { 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 span = Span::new(40, 60);
let data = interface.prepare_pipeline_data( let data = interface.prepare_pipeline_data(
[Value::custom_value( [Value::custom(Box::new(CantSerialize::BadVariant), span)].into_pipeline_data(None),
Box::new(CantSerialize::BadVariant),
span,
)]
.into_pipeline_data(None),
)?; )?;
let value = data let value = data

View file

@ -53,7 +53,7 @@ fn is_false(b: &bool) -> bool {
#[typetag::serde] #[typetag::serde]
impl CustomValue for PluginCustomValue { impl CustomValue for PluginCustomValue {
fn clone_value(&self, span: Span) -> Value { 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 { fn type_name(&self) -> String {
@ -241,12 +241,12 @@ impl PluginCustomValue {
let span = value.span(); let span = value.span();
match value { match value {
// Set source on custom value // Set source on custom value
Value::CustomValue { ref val, .. } => { Value::Custom { ref val, .. } => {
if let Some(custom_value) = val.as_any().downcast_ref::<PluginCustomValue>() { if let Some(custom_value) = val.as_any().downcast_ref::<PluginCustomValue>() {
// Since there's no `as_mut_any()`, we have to copy the whole thing // Since there's no `as_mut_any()`, we have to copy the whole thing
let mut custom_value = custom_value.clone(); let mut custom_value = custom_value.clone();
custom_value.source = Some(source.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(()) Ok(())
} }
@ -272,7 +272,7 @@ impl PluginCustomValue {
let span = value.span(); let span = value.span();
match value { match value {
// Set source on custom value // Set source on custom value
Value::CustomValue { val, .. } => { Value::Custom { val, .. } => {
if let Some(custom_value) = val.as_any().downcast_ref::<PluginCustomValue>() { if let Some(custom_value) = val.as_any().downcast_ref::<PluginCustomValue>() {
if custom_value if custom_value
.source .source
@ -320,13 +320,13 @@ impl PluginCustomValue {
value.recurse_mut(&mut |value| { value.recurse_mut(&mut |value| {
let span = value.span(); let span = value.span();
match value { match value {
Value::CustomValue { ref val, .. } => { Value::Custom { ref val, .. } => {
if val.as_any().downcast_ref::<PluginCustomValue>().is_some() { if val.as_any().downcast_ref::<PluginCustomValue>().is_some() {
// Already a PluginCustomValue // Already a PluginCustomValue
Ok(()) Ok(())
} else { } else {
let serialized = Self::serialize_from_custom_value(&**val, span)?; 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(()) Ok(())
} }
} }
@ -346,10 +346,10 @@ impl PluginCustomValue {
value.recurse_mut(&mut |value| { value.recurse_mut(&mut |value| {
let span = value.span(); let span = value.span();
match value { match value {
Value::CustomValue { ref val, .. } => { Value::Custom { ref val, .. } => {
if let Some(val) = val.as_any().downcast_ref::<PluginCustomValue>() { if let Some(val) = val.as_any().downcast_ref::<PluginCustomValue>() {
let deserialized = val.deserialize_to_custom_value(span)?; let deserialized = val.deserialize_to_custom_value(span)?;
*value = Value::custom_value(deserialized, span); *value = Value::custom(deserialized, span);
Ok(()) Ok(())
} else { } else {
// Already not a PluginCustomValue // Already not a PluginCustomValue
@ -371,7 +371,7 @@ impl PluginCustomValue {
value.recurse_mut(&mut |value| { value.recurse_mut(&mut |value| {
let span = value.span(); let span = value.span();
match value { match value {
Value::CustomValue { ref val, .. } => { Value::Custom { ref val, .. } => {
*value = val.to_base_value(span)?; *value = val.to_base_value(span)?;
Ok(()) Ok(())
} }

View file

@ -231,12 +231,12 @@ fn add_source_nested_closure() -> Result<(), ShellError> {
#[test] #[test]
fn verify_source_error_message() -> Result<(), ShellError> { fn verify_source_error_message() -> Result<(), ShellError> {
let span = Span::new(5, 7); let span = Span::new(5, 7);
let mut ok_val = Value::custom_value(Box::new(test_plugin_custom_value_with_source()), span); let mut ok_val = Value::custom(Box::new(test_plugin_custom_value_with_source()), span);
let mut native_val = Value::custom_value(Box::new(TestCustomValue(32)), span); let mut native_val = Value::custom(Box::new(TestCustomValue(32)), span);
let mut foreign_val = { let mut foreign_val = {
let mut val = test_plugin_custom_value(); let mut val = test_plugin_custom_value();
val.source = Some(Arc::new(PluginSource::new_fake("other"))); 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"); let source = PluginSource::new_fake("test");
@ -407,7 +407,7 @@ fn verify_source_nested_closure() -> Result<(), ShellError> {
#[test] #[test]
fn serialize_in_root() -> Result<(), ShellError> { fn serialize_in_root() -> Result<(), ShellError> {
let span = Span::new(4, 10); 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)?; PluginCustomValue::serialize_custom_values_in(&mut val)?;
assert_eq!(span, val.span()); assert_eq!(span, val.span());
@ -520,7 +520,7 @@ fn serialize_in_closure() -> Result<(), ShellError> {
#[test] #[test]
fn deserialize_in_root() -> Result<(), ShellError> { fn deserialize_in_root() -> Result<(), ShellError> {
let span = Span::new(4, 10); 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)?; PluginCustomValue::deserialize_custom_values_in(&mut val)?;
assert_eq!(span, val.span()); assert_eq!(span, val.span());

View file

@ -9,7 +9,7 @@ pub(crate) struct TestCustomValue(pub i32);
#[typetag::serde] #[typetag::serde]
impl CustomValue for TestCustomValue { impl CustomValue for TestCustomValue {
fn clone_value(&self, span: Span) -> Value { 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 { fn type_name(&self) -> String {

View file

@ -320,7 +320,7 @@ macro_rules! generate_tests {
let data = vec![1, 2, 3, 4, 5]; let data = vec![1, 2, 3, 4, 5];
let span = Span::new(2, 30); let span = Span::new(2, 30);
let value = Value::custom_value( let value = Value::custom(
Box::new(PluginCustomValue::new( Box::new(PluginCustomValue::new(
name.into(), name.into(),
data.clone(), data.clone(),

View file

@ -163,7 +163,7 @@ pub enum Value {
#[serde(rename = "span")] #[serde(rename = "span")]
internal_span: Span, internal_span: Span,
}, },
CustomValue { Custom {
val: Box<dyn CustomValue>, val: Box<dyn CustomValue>,
// note: spans are being refactored out of Value // note: spans are being refactored out of Value
// please use .span() instead of matching this span value // please use .span() instead of matching this span value
@ -252,7 +252,7 @@ impl Clone for Value {
val: val.clone(), val: val.clone(),
internal_span: *internal_span, 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 /// 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> { 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()) Ok(val.as_ref())
} else { } else {
self.cant_convert_to("custom value") 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 /// 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<Box<dyn CustomValue>, ShellError> { pub fn into_custom_value(self) -> Result<Box<dyn CustomValue>, ShellError> {
if let Value::CustomValue { val, .. } = self { if let Value::Custom { val, .. } = self {
Ok(val) Ok(val)
} else { } else {
self.cant_convert_to("custom value") self.cant_convert_to("custom value")
@ -751,7 +751,7 @@ impl Value {
| Value::Nothing { internal_span, .. } | Value::Nothing { internal_span, .. }
| Value::Binary { internal_span, .. } | Value::Binary { internal_span, .. }
| Value::CellPath { internal_span, .. } | Value::CellPath { internal_span, .. }
| Value::CustomValue { internal_span, .. } | Value::Custom { internal_span, .. }
| Value::LazyRecord { internal_span, .. } | Value::LazyRecord { internal_span, .. }
| Value::Error { internal_span, .. } => *internal_span, | Value::Error { internal_span, .. } => *internal_span,
} }
@ -777,7 +777,7 @@ impl Value {
| Value::Nothing { internal_span, .. } | Value::Nothing { internal_span, .. }
| Value::Binary { internal_span, .. } | Value::Binary { internal_span, .. }
| Value::CellPath { internal_span, .. } | Value::CellPath { internal_span, .. }
| Value::CustomValue { internal_span, .. } => *internal_span = new_span, | Value::Custom { internal_span, .. } => *internal_span = new_span,
Value::Error { .. } => (), Value::Error { .. } => (),
} }
} }
@ -838,7 +838,7 @@ impl Value {
Value::Error { .. } => Type::Error, Value::Error { .. } => Type::Error,
Value::Binary { .. } => Type::Binary, Value::Binary { .. } => Type::Binary,
Value::CellPath { .. } => Type::CellPath, 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(), Value::CellPath { val, .. } => val.to_string(),
// If we fail to collapse the custom value, just print <{type_name}> - failure is not // If we fail to collapse the custom value, just print <{type_name}> - failure is not
// that critical here // that critical here
Value::CustomValue { val, .. } => val Value::Custom { val, .. } => val
.to_base_value(span) .to_base_value(span)
.map(|val| val.to_expanded_string(separator, config)) .map(|val| val.to_expanded_string(separator, config))
.unwrap_or_else(|_| format!("<{}>", val.type_name())), .unwrap_or_else(|_| format!("<{}>", val.type_name())),
@ -1118,7 +1118,7 @@ impl Value {
}); });
} }
} }
Value::CustomValue { ref val, .. } => { Value::Custom { ref val, .. } => {
current = current =
match val.follow_path_int(current.span(), *count, *origin_span) { match val.follow_path_int(current.span(), *count, *origin_span) {
Ok(val) => val, Ok(val) => val,
@ -1262,7 +1262,7 @@ impl Value {
current = Value::list(list, span); current = Value::list(list, span);
} }
Value::CustomValue { ref val, .. } => { Value::Custom { ref val, .. } => {
current = match val.follow_path_string( current = match val.follow_path_string(
current.span(), current.span(),
column_name.clone(), column_name.clone(),
@ -1890,7 +1890,7 @@ impl Value {
| Value::Binary { .. } | Value::Binary { .. }
| Value::CellPath { .. } => Ok(()), | Value::CellPath { .. } => Ok(()),
// These could potentially contain values, but we expect the closure to handle them // 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<dyn CustomValue>, span: Span) -> Value { pub fn custom(val: Box<dyn CustomValue>, span: Span) -> Value {
Value::CustomValue { Value::Custom {
val, val,
internal_span: span, 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 /// Note: Only use this for test data, *not* live data, as it will point into unknown source
/// when used in errors. /// when used in errors.
pub fn test_custom_value(val: Box<dyn CustomValue>) -> Value { pub fn test_custom_value(val: Box<dyn CustomValue>) -> 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 /// 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::Error { .. } => Some(Ordering::Less),
Value::Binary { .. } => Some(Ordering::Less), Value::Binary { .. } => Some(Ordering::Less),
Value::CellPath { .. } => 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::Int { val: lhs, .. }, rhs) => match rhs {
Value::Bool { .. } => Some(Ordering::Greater), Value::Bool { .. } => Some(Ordering::Greater),
@ -2278,7 +2278,7 @@ impl PartialOrd for Value {
Value::Error { .. } => Some(Ordering::Less), Value::Error { .. } => Some(Ordering::Less),
Value::Binary { .. } => Some(Ordering::Less), Value::Binary { .. } => Some(Ordering::Less),
Value::CellPath { .. } => 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::Float { val: lhs, .. }, rhs) => match rhs {
Value::Bool { .. } => Some(Ordering::Greater), Value::Bool { .. } => Some(Ordering::Greater),
@ -2299,7 +2299,7 @@ impl PartialOrd for Value {
Value::Error { .. } => Some(Ordering::Less), Value::Error { .. } => Some(Ordering::Less),
Value::Binary { .. } => Some(Ordering::Less), Value::Binary { .. } => Some(Ordering::Less),
Value::CellPath { .. } => 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::Filesize { val: lhs, .. }, rhs) => match rhs {
Value::Bool { .. } => Some(Ordering::Greater), Value::Bool { .. } => Some(Ordering::Greater),
@ -2320,7 +2320,7 @@ impl PartialOrd for Value {
Value::Error { .. } => Some(Ordering::Less), Value::Error { .. } => Some(Ordering::Less),
Value::Binary { .. } => Some(Ordering::Less), Value::Binary { .. } => Some(Ordering::Less),
Value::CellPath { .. } => 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::Duration { val: lhs, .. }, rhs) => match rhs {
Value::Bool { .. } => Some(Ordering::Greater), Value::Bool { .. } => Some(Ordering::Greater),
@ -2341,7 +2341,7 @@ impl PartialOrd for Value {
Value::Error { .. } => Some(Ordering::Less), Value::Error { .. } => Some(Ordering::Less),
Value::Binary { .. } => Some(Ordering::Less), Value::Binary { .. } => Some(Ordering::Less),
Value::CellPath { .. } => 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::Date { val: lhs, .. }, rhs) => match rhs {
Value::Bool { .. } => Some(Ordering::Greater), Value::Bool { .. } => Some(Ordering::Greater),
@ -2362,7 +2362,7 @@ impl PartialOrd for Value {
Value::Error { .. } => Some(Ordering::Less), Value::Error { .. } => Some(Ordering::Less),
Value::Binary { .. } => Some(Ordering::Less), Value::Binary { .. } => Some(Ordering::Less),
Value::CellPath { .. } => 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::Range { val: lhs, .. }, rhs) => match rhs {
Value::Bool { .. } => Some(Ordering::Greater), Value::Bool { .. } => Some(Ordering::Greater),
@ -2383,7 +2383,7 @@ impl PartialOrd for Value {
Value::Error { .. } => Some(Ordering::Less), Value::Error { .. } => Some(Ordering::Less),
Value::Binary { .. } => Some(Ordering::Less), Value::Binary { .. } => Some(Ordering::Less),
Value::CellPath { .. } => 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::String { val: lhs, .. }, rhs) => match rhs {
Value::Bool { .. } => Some(Ordering::Greater), Value::Bool { .. } => Some(Ordering::Greater),
@ -2404,7 +2404,7 @@ impl PartialOrd for Value {
Value::Error { .. } => Some(Ordering::Less), Value::Error { .. } => Some(Ordering::Less),
Value::Binary { .. } => Some(Ordering::Less), Value::Binary { .. } => Some(Ordering::Less),
Value::CellPath { .. } => 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::Glob { val: lhs, .. }, rhs) => match rhs {
Value::Bool { .. } => Some(Ordering::Greater), Value::Bool { .. } => Some(Ordering::Greater),
@ -2425,7 +2425,7 @@ impl PartialOrd for Value {
Value::Error { .. } => Some(Ordering::Less), Value::Error { .. } => Some(Ordering::Less),
Value::Binary { .. } => Some(Ordering::Less), Value::Binary { .. } => Some(Ordering::Less),
Value::CellPath { .. } => 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::Record { val: lhs, .. }, rhs) => match rhs {
Value::Bool { .. } => Some(Ordering::Greater), Value::Bool { .. } => Some(Ordering::Greater),
@ -2465,7 +2465,7 @@ impl PartialOrd for Value {
Value::Error { .. } => Some(Ordering::Less), Value::Error { .. } => Some(Ordering::Less),
Value::Binary { .. } => Some(Ordering::Less), Value::Binary { .. } => Some(Ordering::Less),
Value::CellPath { .. } => 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::List { vals: lhs, .. }, rhs) => match rhs {
Value::Bool { .. } => Some(Ordering::Greater), Value::Bool { .. } => Some(Ordering::Greater),
@ -2486,7 +2486,7 @@ impl PartialOrd for Value {
Value::Error { .. } => Some(Ordering::Less), Value::Error { .. } => Some(Ordering::Less),
Value::Binary { .. } => Some(Ordering::Less), Value::Binary { .. } => Some(Ordering::Less),
Value::CellPath { .. } => 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::Block { val: lhs, .. }, rhs) => match rhs {
Value::Bool { .. } => Some(Ordering::Greater), Value::Bool { .. } => Some(Ordering::Greater),
@ -2507,7 +2507,7 @@ impl PartialOrd for Value {
Value::Error { .. } => Some(Ordering::Less), Value::Error { .. } => Some(Ordering::Less),
Value::Binary { .. } => Some(Ordering::Less), Value::Binary { .. } => Some(Ordering::Less),
Value::CellPath { .. } => 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::Closure { val: lhs, .. }, rhs) => match rhs {
Value::Bool { .. } => Some(Ordering::Greater), Value::Bool { .. } => Some(Ordering::Greater),
@ -2528,7 +2528,7 @@ impl PartialOrd for Value {
Value::Error { .. } => Some(Ordering::Less), Value::Error { .. } => Some(Ordering::Less),
Value::Binary { .. } => Some(Ordering::Less), Value::Binary { .. } => Some(Ordering::Less),
Value::CellPath { .. } => Some(Ordering::Less), Value::CellPath { .. } => Some(Ordering::Less),
Value::CustomValue { .. } => Some(Ordering::Less), Value::Custom { .. } => Some(Ordering::Less),
}, },
(Value::Nothing { .. }, rhs) => match rhs { (Value::Nothing { .. }, rhs) => match rhs {
Value::Bool { .. } => Some(Ordering::Greater), Value::Bool { .. } => Some(Ordering::Greater),
@ -2549,7 +2549,7 @@ impl PartialOrd for Value {
Value::Error { .. } => Some(Ordering::Less), Value::Error { .. } => Some(Ordering::Less),
Value::Binary { .. } => Some(Ordering::Less), Value::Binary { .. } => Some(Ordering::Less),
Value::CellPath { .. } => Some(Ordering::Less), Value::CellPath { .. } => Some(Ordering::Less),
Value::CustomValue { .. } => Some(Ordering::Less), Value::Custom { .. } => Some(Ordering::Less),
}, },
(Value::Error { .. }, rhs) => match rhs { (Value::Error { .. }, rhs) => match rhs {
Value::Bool { .. } => Some(Ordering::Greater), Value::Bool { .. } => Some(Ordering::Greater),
@ -2570,7 +2570,7 @@ impl PartialOrd for Value {
Value::Error { .. } => Some(Ordering::Equal), Value::Error { .. } => Some(Ordering::Equal),
Value::Binary { .. } => Some(Ordering::Less), Value::Binary { .. } => Some(Ordering::Less),
Value::CellPath { .. } => 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::Binary { val: lhs, .. }, rhs) => match rhs {
Value::Bool { .. } => Some(Ordering::Greater), Value::Bool { .. } => Some(Ordering::Greater),
@ -2591,7 +2591,7 @@ impl PartialOrd for Value {
Value::Error { .. } => Some(Ordering::Greater), Value::Error { .. } => Some(Ordering::Greater),
Value::Binary { val: rhs, .. } => lhs.partial_cmp(rhs), Value::Binary { val: rhs, .. } => lhs.partial_cmp(rhs),
Value::CellPath { .. } => Some(Ordering::Less), Value::CellPath { .. } => Some(Ordering::Less),
Value::CustomValue { .. } => Some(Ordering::Less), Value::Custom { .. } => Some(Ordering::Less),
}, },
(Value::CellPath { val: lhs, .. }, rhs) => match rhs { (Value::CellPath { val: lhs, .. }, rhs) => match rhs {
Value::Bool { .. } => Some(Ordering::Greater), Value::Bool { .. } => Some(Ordering::Greater),
@ -2612,9 +2612,9 @@ impl PartialOrd for Value {
Value::Error { .. } => Some(Ordering::Greater), Value::Error { .. } => Some(Ordering::Greater),
Value::Binary { .. } => Some(Ordering::Greater), Value::Binary { .. } => Some(Ordering::Greater),
Value::CellPath { val: rhs, .. } => lhs.partial_cmp(rhs), 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) => { (Value::LazyRecord { val, .. }, rhs) => {
if let Ok(val) = val.collect() { if let Ok(val) = val.collect() {
val.partial_cmp(rhs) 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) lhs.operation(self.span(), Operator::Math(Math::Plus), op, rhs)
} }
@ -2729,7 +2729,7 @@ impl Value {
val.extend(rhs); val.extend(rhs);
Ok(Value::binary(val, span)) 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) lhs.operation(self.span(), Operator::Math(Math::Append), op, rhs)
} }
_ => Err(ShellError::OperatorMismatch { _ => 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) lhs.operation(self.span(), Operator::Math(Math::Minus), op, rhs)
} }
@ -2862,7 +2862,7 @@ impl Value {
(Value::Float { val: lhs, .. }, Value::Duration { val: rhs, .. }) => { (Value::Float { val: lhs, .. }, Value::Duration { val: rhs, .. }) => {
Ok(Value::duration((*lhs * *rhs as f64) as i64, span)) 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) lhs.operation(self.span(), Operator::Math(Math::Multiply), op, rhs)
} }
_ => Err(ShellError::OperatorMismatch { _ => Err(ShellError::OperatorMismatch {
@ -2965,7 +2965,7 @@ impl Value {
Err(ShellError::DivisionByZero { span: op }) 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) lhs.operation(self.span(), Operator::Math(Math::Divide), op, rhs)
} }
@ -3101,7 +3101,7 @@ impl Value {
Err(ShellError::DivisionByZero { span: op }) 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) 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<Value, ShellError> { pub fn lt(&self, op: Span, rhs: &Value, span: Span) -> Result<Value, ShellError> {
if let (Value::CustomValue { val: lhs, .. }, rhs) = (self, rhs) { if let (Value::Custom { val: lhs, .. }, rhs) = (self, rhs) {
return lhs.operation( return lhs.operation(
self.span(), self.span(),
Operator::Comparison(Comparison::LessThan), Operator::Comparison(Comparison::LessThan),
@ -3156,7 +3156,7 @@ impl Value {
} }
pub fn lte(&self, op: Span, rhs: &Value, span: Span) -> Result<Value, ShellError> { pub fn lte(&self, op: Span, rhs: &Value, span: Span) -> Result<Value, ShellError> {
if let (Value::CustomValue { val: lhs, .. }, rhs) = (self, rhs) { if let (Value::Custom { val: lhs, .. }, rhs) = (self, rhs) {
return lhs.operation( return lhs.operation(
self.span(), self.span(),
Operator::Comparison(Comparison::LessThanOrEqual), Operator::Comparison(Comparison::LessThanOrEqual),
@ -3194,7 +3194,7 @@ impl Value {
} }
pub fn gt(&self, op: Span, rhs: &Value, span: Span) -> Result<Value, ShellError> { pub fn gt(&self, op: Span, rhs: &Value, span: Span) -> Result<Value, ShellError> {
if let (Value::CustomValue { val: lhs, .. }, rhs) = (self, rhs) { if let (Value::Custom { val: lhs, .. }, rhs) = (self, rhs) {
return lhs.operation( return lhs.operation(
self.span(), self.span(),
Operator::Comparison(Comparison::GreaterThan), Operator::Comparison(Comparison::GreaterThan),
@ -3232,7 +3232,7 @@ impl Value {
} }
pub fn gte(&self, op: Span, rhs: &Value, span: Span) -> Result<Value, ShellError> { pub fn gte(&self, op: Span, rhs: &Value, span: Span) -> Result<Value, ShellError> {
if let (Value::CustomValue { val: lhs, .. }, rhs) = (self, rhs) { if let (Value::Custom { val: lhs, .. }, rhs) = (self, rhs) {
return lhs.operation( return lhs.operation(
self.span(), self.span(),
Operator::Comparison(Comparison::GreaterThanOrEqual), Operator::Comparison(Comparison::GreaterThanOrEqual),
@ -3274,7 +3274,7 @@ impl Value {
} }
pub fn eq(&self, op: Span, rhs: &Value, span: Span) -> Result<Value, ShellError> { pub fn eq(&self, op: Span, rhs: &Value, span: Span) -> Result<Value, ShellError> {
if let (Value::CustomValue { val: lhs, .. }, rhs) = (self, rhs) { if let (Value::Custom { val: lhs, .. }, rhs) = (self, rhs) {
return lhs.operation( return lhs.operation(
self.span(), self.span(),
Operator::Comparison(Comparison::Equal), Operator::Comparison(Comparison::Equal),
@ -3302,7 +3302,7 @@ impl Value {
} }
pub fn ne(&self, op: Span, rhs: &Value, span: Span) -> Result<Value, ShellError> { pub fn ne(&self, op: Span, rhs: &Value, span: Span) -> Result<Value, ShellError> {
if let (Value::CustomValue { val: lhs, .. }, rhs) = (self, rhs) { if let (Value::Custom { val: lhs, .. }, rhs) = (self, rhs) {
return lhs.operation( return lhs.operation(
self.span(), self.span(),
Operator::Comparison(Comparison::NotEqual), Operator::Comparison(Comparison::NotEqual),
@ -3364,7 +3364,7 @@ impl Value {
span, span,
)) ))
} }
(Value::CustomValue { val: lhs, .. }, rhs) => { (Value::Custom { val: lhs, .. }, rhs) => {
lhs.operation(self.span(), Operator::Comparison(Comparison::In), op, rhs) lhs.operation(self.span(), Operator::Comparison(Comparison::In), op, rhs)
} }
_ => Err(ShellError::OperatorMismatch { _ => Err(ShellError::OperatorMismatch {
@ -3412,7 +3412,7 @@ impl Value {
span, span,
)) ))
} }
(Value::CustomValue { val: lhs, .. }, rhs) => lhs.operation( (Value::Custom { val: lhs, .. }, rhs) => lhs.operation(
self.span(), self.span(),
Operator::Comparison(Comparison::NotIn), Operator::Comparison(Comparison::NotIn),
op, op,
@ -3476,7 +3476,7 @@ impl Value {
span, span,
)) ))
} }
(Value::CustomValue { val: lhs, .. }, rhs) => lhs.operation( (Value::Custom { val: lhs, .. }, rhs) => lhs.operation(
span, span,
if invert { if invert {
Operator::Comparison(Comparison::NotRegexMatch) Operator::Comparison(Comparison::NotRegexMatch)
@ -3501,7 +3501,7 @@ impl Value {
(Value::String { val: lhs, .. }, Value::String { val: rhs, .. }) => { (Value::String { val: lhs, .. }, Value::String { val: rhs, .. }) => {
Ok(Value::bool(lhs.starts_with(rhs), span)) Ok(Value::bool(lhs.starts_with(rhs), span))
} }
(Value::CustomValue { val: lhs, .. }, rhs) => lhs.operation( (Value::Custom { val: lhs, .. }, rhs) => lhs.operation(
self.span(), self.span(),
Operator::Comparison(Comparison::StartsWith), Operator::Comparison(Comparison::StartsWith),
op, op,
@ -3522,7 +3522,7 @@ impl Value {
(Value::String { val: lhs, .. }, Value::String { val: rhs, .. }) => { (Value::String { val: lhs, .. }, Value::String { val: rhs, .. }) => {
Ok(Value::bool(lhs.ends_with(rhs), span)) Ok(Value::bool(lhs.ends_with(rhs), span))
} }
(Value::CustomValue { val: lhs, .. }, rhs) => lhs.operation( (Value::Custom { val: lhs, .. }, rhs) => lhs.operation(
self.span(), self.span(),
Operator::Comparison(Comparison::EndsWith), Operator::Comparison(Comparison::EndsWith),
op, op,
@ -3543,7 +3543,7 @@ impl Value {
(Value::Int { val: lhs, .. }, Value::Int { val: rhs, .. }) => { (Value::Int { val: lhs, .. }, Value::Int { val: rhs, .. }) => {
Ok(Value::int(*lhs << rhs, span)) 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) lhs.operation(span, Operator::Bits(Bits::ShiftLeft), op, rhs)
} }
_ => Err(ShellError::OperatorMismatch { _ => Err(ShellError::OperatorMismatch {
@ -3561,7 +3561,7 @@ impl Value {
(Value::Int { val: lhs, .. }, Value::Int { val: rhs, .. }) => { (Value::Int { val: lhs, .. }, Value::Int { val: rhs, .. }) => {
Ok(Value::int(*lhs >> rhs, span)) 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) lhs.operation(span, Operator::Bits(Bits::ShiftRight), op, rhs)
} }
_ => Err(ShellError::OperatorMismatch { _ => Err(ShellError::OperatorMismatch {
@ -3579,7 +3579,7 @@ impl Value {
(Value::Int { val: lhs, .. }, Value::Int { val: rhs, .. }) => { (Value::Int { val: lhs, .. }, Value::Int { val: rhs, .. }) => {
Ok(Value::int(*lhs | rhs, span)) 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) lhs.operation(span, Operator::Bits(Bits::BitOr), op, rhs)
} }
_ => Err(ShellError::OperatorMismatch { _ => Err(ShellError::OperatorMismatch {
@ -3597,7 +3597,7 @@ impl Value {
(Value::Int { val: lhs, .. }, Value::Int { val: rhs, .. }) => { (Value::Int { val: lhs, .. }, Value::Int { val: rhs, .. }) => {
Ok(Value::int(*lhs ^ rhs, span)) 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) lhs.operation(span, Operator::Bits(Bits::BitXor), op, rhs)
} }
_ => Err(ShellError::OperatorMismatch { _ => Err(ShellError::OperatorMismatch {
@ -3615,7 +3615,7 @@ impl Value {
(Value::Int { val: lhs, .. }, Value::Int { val: rhs, .. }) => { (Value::Int { val: lhs, .. }, Value::Int { val: rhs, .. }) => {
Ok(Value::int(*lhs & rhs, span)) 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) lhs.operation(span, Operator::Bits(Bits::BitAnd), op, rhs)
} }
_ => Err(ShellError::OperatorMismatch { _ => Err(ShellError::OperatorMismatch {
@ -3665,7 +3665,7 @@ impl Value {
Err(ShellError::DivisionByZero { span: op }) Err(ShellError::DivisionByZero { span: op })
} }
} }
(Value::CustomValue { val: lhs, .. }, rhs) => { (Value::Custom { val: lhs, .. }, rhs) => {
lhs.operation(span, Operator::Math(Math::Modulo), op, rhs) lhs.operation(span, Operator::Math(Math::Modulo), op, rhs)
} }
@ -3684,7 +3684,7 @@ impl Value {
(Value::Bool { val: lhs, .. }, Value::Bool { val: rhs, .. }) => { (Value::Bool { val: lhs, .. }, Value::Bool { val: rhs, .. }) => {
Ok(Value::bool(*lhs && *rhs, span)) 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) lhs.operation(span, Operator::Boolean(Boolean::And), op, rhs)
} }
_ => Err(ShellError::OperatorMismatch { _ => Err(ShellError::OperatorMismatch {
@ -3702,7 +3702,7 @@ impl Value {
(Value::Bool { val: lhs, .. }, Value::Bool { val: rhs, .. }) => { (Value::Bool { val: lhs, .. }, Value::Bool { val: rhs, .. }) => {
Ok(Value::bool(*lhs || *rhs, span)) 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) lhs.operation(span, Operator::Boolean(Boolean::Or), op, rhs)
} }
_ => Err(ShellError::OperatorMismatch { _ => Err(ShellError::OperatorMismatch {
@ -3720,7 +3720,7 @@ impl Value {
(Value::Bool { val: lhs, .. }, Value::Bool { val: rhs, .. }) => { (Value::Bool { val: lhs, .. }, Value::Bool { val: rhs, .. }) => {
Ok(Value::bool((*lhs && !*rhs) || (!*lhs && *rhs), span)) 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) lhs.operation(span, Operator::Boolean(Boolean::Xor), op, rhs)
} }
_ => Err(ShellError::OperatorMismatch { _ => Err(ShellError::OperatorMismatch {
@ -3751,7 +3751,7 @@ impl Value {
(Value::Float { val: lhs, .. }, Value::Float { val: rhs, .. }) => { (Value::Float { val: lhs, .. }, Value::Float { val: rhs, .. }) => {
Ok(Value::float(lhs.powf(*rhs), span)) 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) lhs.operation(span, Operator::Math(Math::Pow), op, rhs)
} }

View file

@ -15,13 +15,13 @@ impl CoolCustomValue {
} }
pub fn into_value(self, span: Span) -> Value { 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<Self, ShellError> { pub fn try_from_value(value: &Value) -> Result<Self, ShellError> {
let span = value.span(); let span = value.span();
match value { match value {
Value::CustomValue { val, .. } => { Value::Custom { val, .. } => {
if let Some(cool) = val.as_any().downcast_ref::<Self>() { if let Some(cool) = val.as_any().downcast_ref::<Self>() {
Ok(cool.clone()) Ok(cool.clone())
} else { } else {
@ -46,7 +46,7 @@ impl CoolCustomValue {
#[typetag::serde] #[typetag::serde]
impl CustomValue for CoolCustomValue { impl CustomValue for CoolCustomValue {
fn clone_value(&self, span: Span) -> Value { 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 { fn type_name(&self) -> String {
@ -94,7 +94,7 @@ impl CustomValue for CoolCustomValue {
} }
fn partial_cmp(&self, other: &Value) -> Option<Ordering> { fn partial_cmp(&self, other: &Value) -> Option<Ordering> {
if let Value::CustomValue { val, .. } = other { if let Value::Custom { val, .. } = other {
val.as_any() val.as_any()
.downcast_ref() .downcast_ref()
.and_then(|other: &CoolCustomValue| PartialOrd::partial_cmp(self, other)) .and_then(|other: &CoolCustomValue| PartialOrd::partial_cmp(self, other))
@ -118,7 +118,7 @@ impl CustomValue for CoolCustomValue {
.ok() .ok()
.and_then(|c| c.as_any().downcast_ref::<CoolCustomValue>()) .and_then(|c| c.as_any().downcast_ref::<CoolCustomValue>())
{ {
Ok(Value::custom_value( Ok(Value::custom(
Box::new(CoolCustomValue { Box::new(CoolCustomValue {
cool: format!("{}{}", self.cool, right.cool), cool: format!("{}{}", self.cool, right.cool),
}), }),

View file

@ -16,7 +16,7 @@ impl DropCheckValue {
} }
pub(crate) fn into_value(self, span: Span) -> Value { 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) { pub(crate) fn notify(&self) {

View file

@ -16,13 +16,13 @@ impl SecondCustomValue {
} }
pub fn into_value(self, span: Span) -> Value { 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<Self, ShellError> { pub fn try_from_value(value: &Value) -> Result<Self, ShellError> {
let span = value.span(); let span = value.span();
match value { match value {
Value::CustomValue { val, .. } => match val.as_any().downcast_ref::<Self>() { Value::Custom { val, .. } => match val.as_any().downcast_ref::<Self>() {
Some(value) => Ok(value.clone()), Some(value) => Ok(value.clone()),
None => Err(ShellError::CantConvert { None => Err(ShellError::CantConvert {
to_type: "cool".into(), to_type: "cool".into(),
@ -44,7 +44,7 @@ impl SecondCustomValue {
#[typetag::serde] #[typetag::serde]
impl CustomValue for SecondCustomValue { impl CustomValue for SecondCustomValue {
fn clone_value(&self, span: nu_protocol::Span) -> Value { 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 { fn type_name(&self) -> String {
@ -62,7 +62,7 @@ impl CustomValue for SecondCustomValue {
} }
fn partial_cmp(&self, other: &Value) -> Option<Ordering> { fn partial_cmp(&self, other: &Value) -> Option<Ordering> {
if let Value::CustomValue { val, .. } = other { if let Value::Custom { val, .. } = other {
val.as_any() val.as_any()
.downcast_ref() .downcast_ref()
.and_then(|other: &SecondCustomValue| PartialOrd::partial_cmp(self, other)) .and_then(|other: &SecondCustomValue| PartialOrd::partial_cmp(self, other))