mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 14:40:06 +02:00
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:
committed by
GitHub
parent
dfbbacfdf8
commit
b19da158d5
@ -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))
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ impl Command for LazyCollect {
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
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))
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
|
@ -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<std::cmp::Ordering> {
|
||||
match other {
|
||||
Value::CustomValue { val, .. } => val
|
||||
Value::Custom { val, .. } => val
|
||||
.as_any()
|
||||
.downcast_ref::<Self>()
|
||||
.and_then(|other| self.is_equal(other)),
|
||||
|
@ -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<Self, ShellError> {
|
||||
let span = value.span();
|
||||
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 {
|
||||
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::<Self>().is_some()
|
||||
} else {
|
||||
false
|
||||
|
@ -20,7 +20,7 @@ impl NuDataFrame {
|
||||
) -> Result<Value, ShellError> {
|
||||
let rhs_span = right.span();
|
||||
match right {
|
||||
Value::CustomValue { val: rhs, .. } => {
|
||||
Value::Custom { val: rhs, .. } => {
|
||||
let rhs = rhs.as_any().downcast_ref::<NuDataFrame>().ok_or_else(|| {
|
||||
ShellError::DowncastNotPossible {
|
||||
msg: "Unable to create dataframe".to_string(),
|
||||
|
@ -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<Value, ShellError> {
|
||||
let rhs_span = right.span();
|
||||
match right {
|
||||
Value::CustomValue { val: rhs, .. } => {
|
||||
Value::Custom { val: rhs, .. } => {
|
||||
let rhs = rhs.as_any().downcast_ref::<NuExpression>().ok_or_else(|| {
|
||||
ShellError::DowncastNotPossible {
|
||||
msg: "Unable to create expression".into(),
|
||||
|
@ -55,13 +55,13 @@ impl From<Expr> 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<Self, ShellError> {
|
||||
let span = value.span();
|
||||
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())),
|
||||
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::<Self>().is_some(),
|
||||
Value::Custom { val, .. } => val.as_any().downcast_ref::<Self>().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<ExtractedExpr, ShellError> {
|
||||
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
|
||||
|
@ -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 {
|
||||
|
@ -90,9 +90,9 @@ impl NuLazyFrame {
|
||||
pub fn into_value(self, span: Span) -> Result<Value, ShellError> {
|
||||
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<Self, ShellError> {
|
||||
let span = value.span();
|
||||
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 {
|
||||
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::<Self>().is_some()
|
||||
} else {
|
||||
false
|
||||
|
@ -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 {
|
||||
|
@ -74,7 +74,7 @@ impl From<LazyGroupBy> 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<Self, ShellError> {
|
||||
let span = value.span();
|
||||
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 {
|
||||
group_by: group.group_by.clone(),
|
||||
schema: group.schema.clone(),
|
||||
|
@ -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 {
|
||||
|
@ -51,13 +51,13 @@ impl From<ChainedThen> 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<Self, ShellError> {
|
||||
let span = value.span();
|
||||
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()),
|
||||
None => Err(ShellError::CantConvert {
|
||||
to_type: "when expression".into(),
|
||||
|
Reference in New Issue
Block a user