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
@ -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<Self, ShellError> {
|
||||
let span = value.span();
|
||||
match value {
|
||||
Value::CustomValue { val, .. } => {
|
||||
Value::Custom { val, .. } => {
|
||||
if let Some(cool) = val.as_any().downcast_ref::<Self>() {
|
||||
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<Ordering> {
|
||||
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::<CoolCustomValue>())
|
||||
{
|
||||
Ok(Value::custom_value(
|
||||
Ok(Value::custom(
|
||||
Box::new(CoolCustomValue {
|
||||
cool: format!("{}{}", self.cool, right.cool),
|
||||
}),
|
||||
|
@ -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) {
|
||||
|
@ -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<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(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<Ordering> {
|
||||
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))
|
||||
|
Reference in New Issue
Block a user