nu_protocol

Trait CustomValue

Source
pub trait CustomValue:
    Debug
    + Send
    + Sync
    + Serialize
    + Deserialize {
    // Required methods
    fn clone_value(&self, span: Span) -> Value;
    fn type_name(&self) -> String;
    fn to_base_value(&self, span: Span) -> Result<Value, ShellError>;
    fn as_any(&self) -> &dyn Any;
    fn as_mut_any(&mut self) -> &mut dyn Any;

    // Provided methods
    fn follow_path_int(
        &self,
        self_span: Span,
        index: usize,
        path_span: Span,
    ) -> Result<Value, ShellError> { ... }
    fn follow_path_string(
        &self,
        self_span: Span,
        column_name: String,
        path_span: Span,
    ) -> Result<Value, ShellError> { ... }
    fn partial_cmp(&self, _other: &Value) -> Option<Ordering> { ... }
    fn operation(
        &self,
        lhs_span: Span,
        operator: Operator,
        op: Span,
        right: &Value,
    ) -> Result<Value, ShellError> { ... }
    fn notify_plugin_on_drop(&self) -> bool { ... }
}
Expand description

Trait definition for a custom Value type

Required Methods§

Source

fn clone_value(&self, span: Span) -> Value

Custom Clone implementation

This can reemit a Value::CustomValue(Self, span) or materialize another representation if necessary.

Source

fn type_name(&self) -> String

The friendly type name to show for the custom value, e.g. in describe and in error messages. This does not have to be the same as the name of the struct or enum, but conventionally often is.

Source

fn to_base_value(&self, span: Span) -> Result<Value, ShellError>

Converts the custom value to a base nushell value.

This imposes the requirement that you can represent the custom value in some form using the Value representations that already exist in nushell

Source

fn as_any(&self) -> &dyn Any

Any representation used to downcast object to its original type

Source

fn as_mut_any(&mut self) -> &mut dyn Any

Any representation used to downcast object to its original type (mutable reference)

Provided Methods§

Source

fn follow_path_int( &self, self_span: Span, index: usize, path_span: Span, ) -> Result<Value, ShellError>

Follow cell path by numeric index (e.g. rows)

Source

fn follow_path_string( &self, self_span: Span, column_name: String, path_span: Span, ) -> Result<Value, ShellError>

Follow cell path by string key (e.g. columns)

Source

fn partial_cmp(&self, _other: &Value) -> Option<Ordering>

ordering with other value (see std::cmp::PartialOrd)

Source

fn operation( &self, lhs_span: Span, operator: Operator, op: Span, right: &Value, ) -> Result<Value, ShellError>

Definition of an operation between the object that implements the trait and another Value.

The Operator enum is used to indicate the expected operation.

Default impl raises ShellError::UnsupportedOperator.

Source

fn notify_plugin_on_drop(&self) -> bool

For custom values in plugins: return true here if you would like to be notified when all copies of this custom value are dropped in the engine.

The notification will take place via custom_value_dropped() on the plugin type.

The default is false.

Trait Implementations§

Source§

impl<'typetag> Serialize for dyn CustomValue + 'typetag

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<'typetag> Serialize for dyn CustomValue + Send + 'typetag

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<'typetag> Serialize for dyn CustomValue + Send + Sync + 'typetag

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<'typetag> Serialize for dyn CustomValue + Sync + 'typetag

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Implementors§