Enum Value

Source
pub enum Value {
Show 14 variants Null, String(String), Bool(bool), U64(u64), I64(i64), F64(f64), Decimal(Decimal), U128(u128), I128(i128), B32([u8; 32]), B64([u8; 64]), Bytes(Bytes), Array(Vec<Self>), Map(Map),
}
Expand description

Value represents all values that nodes can use as input and output.

§Data Types

§Node Input

Node receives a flow_value::Map as its input. It is possible to use the map directly, but it is often preferred to convert it to structs or enums of your choice.

Value implements Deserializer, therefore it can be converted to any types supported by Serde. We provide 2 helpers:

§Node Output

Node returns a flow_value::Map as its output.

Building the output directly with flow_value::map! and flow_value::array! macros:

let value = flow_value::map! {
    "customer_name" => "John",
    "items" => flow_value::array![1, 2, 3],
};

Value also implements Serializer, you can use flow_value::to_map to convert any type T: Serialize into value::Map.

#[derive(serde::Serialize)]
struct Order {
    customer_name: String,
    items: Vec<i32>,
}

flow_value::to_map(&Order {
    customer_name: "John".to_owned(),
    items: [1, 2, 3].into(),
})
.unwrap();

§JSON representation

When using Value in database and HTTP APIs, it is converted to a JSON object:

{
    "<variant identifier>": <data>
}

Identifiers of each enum variant:

See variant’s documentation to see how data are encoded.

Use serde_json to encode and decode Value as JSON:

use flow_value::Value;

let value = Value::U64(10);

// encode Value to JSON
let json = serde_json::to_string(&value).unwrap();
assert_eq!(json, r#"{"U":"10"}"#);

// decode JSON to Value
let value1 = serde_json::from_str::<Value>(&json).unwrap();
assert_eq!(value1, value);

Variants§

§

Null

JSON representation:

{ "N": 0 }
§

String(String)

UTF-8 string.

JSON representation:

{ "S": "hello" }
§

Bool(bool)

JSON representation:

{ "B": true }
§

U64(u64)

JSON representation:

{ "U": "100" }

Numbers are encoded as JSON string to avoid losing precision when reading them in Javascript/Typescript.

§

I64(i64)

JSON representation:

{ "I": "-100" }
§

F64(f64)

JSON representation:

{ "F": "0.0" }

Scientific notation is supported:

{ "F": "1e9" }
§

Decimal(Decimal)

rust_decimal::Decimal, suitable for financial calculations.

JSON representation:

{ "D": "3.1415926535897932384626433832" }
§

U128(u128)

JSON representation:

{ "U1": "340282366920938463463374607431768211455" }
§

I128(i128)

JSON representation:

{ "I1": "-170141183460469231731687303715884105728" }
§

B32([u8; 32])

32-bytes binary values, usually a Solana public key.

JSON representation: encoded as a base-58 string

{ "B3": "FMQUifdAHTytSxhiK4N7LmpvKRZaUmBnNnZmzFsdTPHB" }
§

B64([u8; 64])

64-bytes binary values, usually a Solana signature or keypair.

JSON representation: encoded as a base-58 string

{ "B6": "4onDpbfeT7nNN9MNMvTEZRn6pbtrQc1pdTBJB4a7HbfhAE6c5bkbuuFfYtkqs99hAqp5o6j7W1VyuKDxCn79k3Tk" }
§

Bytes(Bytes)

Binary values with length other than 32 and 64.

JSON representation: encoded as a base-64 string

{ "BY": "UmFpbnk=" }
§

Array(Vec<Self>)

An array of Value. Array can contains other arrays, maps, ect. Array elements do not have to be of the same type.

JSON representation:

Example array containing a number and a string:

{
    "A": [
        { "U": 0 },
        { "S": "hello" }
    ]
}
§

Map(Map)

A key-value map, implemented with indexmap::IndexMap, will preserve insertion order. Keys are strings and values can be any Value.

JSON representation:

{
    "M": {
        "first name": { "S": "John" },
        "age": { "U": "20" }
    }
}

Implementations§

Source§

impl Value

Source

pub const fn kind(&self) -> Variant

Source§

impl Value

Source

pub fn to_bincode(&self) -> Result<Vec<u8>, EncodeError>

Source

pub fn from_bincode(data: &[u8]) -> Result<Self, DecodeError>

Source§

impl Value

Source

pub fn new_keypair_bs58(s: &str) -> Result<Self, Error>

Source

pub fn normalize(self) -> Self

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Value

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<C> Decode<C> for Value

Source§

fn decode<D: Decoder<Context = C>>(d: &mut D) -> Result<Self, DecodeError>

Attempt to decode this type with the given Decode.
Source§

impl Default for Value

Source§

fn default() -> Value

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Value

Source§

fn deserialize<D>(d: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Turn any Deserializer into Value, intended to be used with Value as Deserializer.

Source§

impl<'de> Deserializer<'de> for Value

Source§

type Error = Error

The error type that can be returned if some error occurs during deserialization.
Source§

fn is_human_readable(&self) -> bool

Determine whether Deserialize implementations should expect to deserialize their human-readable form. Read more
Source§

fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Require the Deserializer to figure out how to drive the visitor based on what data type is in the input. Read more
Source§

fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an optional value. Read more
Source§

fn deserialize_newtype_struct<V>( self, name: &'static str, visitor: V, ) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a newtype struct with a particular name.
Source§

fn deserialize_enum<V>( self, name: &'static str, _: &'static [&'static str], visitor: V, ) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an enum value with a particular name and possible variants.
Source§

fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a byte array and does not benefit from taking ownership of buffered data owned by the Deserializer. Read more
Source§

fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a byte array and would benefit from taking ownership of buffered data owned by the Deserializer. Read more
Source§

fn deserialize_bool<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a bool value.
Source§

fn deserialize_i8<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an i8 value.
Source§

fn deserialize_i16<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an i16 value.
Source§

fn deserialize_i32<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an i32 value.
Source§

fn deserialize_i64<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an i64 value.
Source§

fn deserialize_i128<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an i128 value. Read more
Source§

fn deserialize_u8<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a u8 value.
Source§

fn deserialize_u16<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a u16 value.
Source§

fn deserialize_u32<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a u32 value.
Source§

fn deserialize_u64<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a u64 value.
Source§

fn deserialize_u128<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an u128 value. Read more
Source§

fn deserialize_f32<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a f32 value.
Source§

fn deserialize_f64<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a f64 value.
Source§

fn deserialize_char<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a char value.
Source§

fn deserialize_str<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a string value and does not benefit from taking ownership of buffered data owned by the Deserializer. Read more
Source§

fn deserialize_string<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a string value and would benefit from taking ownership of buffered data owned by the Deserializer. Read more
Source§

fn deserialize_unit<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a unit value.
Source§

fn deserialize_unit_struct<V>( self, name: &'static str, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a unit struct with a particular name.
Source§

fn deserialize_seq<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a sequence of values.
Source§

fn deserialize_tuple<V>( self, len: usize, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a sequence of values and knows how many values there are without looking at the serialized data.
Source§

fn deserialize_tuple_struct<V>( self, name: &'static str, len: usize, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a tuple struct with a particular name and number of fields.
Source§

fn deserialize_map<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a map of key-value pairs.
Source§

fn deserialize_struct<V>( self, name: &'static str, fields: &'static [&'static str], visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a struct with a particular name and fields.
Source§

fn deserialize_identifier<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting the name of a struct field or the discriminant of an enum variant.
Source§

fn deserialize_ignored_any<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type needs to deserialize a value whose type doesn’t matter because it is ignored. Read more
Source§

impl Encode for Value

Source§

fn encode<E: Encoder>(&self, e: &mut E) -> Result<(), EncodeError>

Encode a given type.
Source§

impl From<&[u8]> for Value

Source§

fn from(x: &[u8]) -> Self

Converts to this type from the input type.
Source§

impl From<&str> for Value

Source§

fn from(x: &str) -> Self

Converts to this type from the input type.
Source§

impl From<[u8; 32]> for Value

Source§

fn from(x: [u8; 32]) -> Self

Converts to this type from the input type.
Source§

impl From<[u8; 64]> for Value

Source§

fn from(x: [u8; 64]) -> Self

Converts to this type from the input type.
Source§

impl From<Bytes> for Value

Source§

fn from(x: Bytes) -> Self

Converts to this type from the input type.
Source§

impl From<Decimal> for Value

Source§

fn from(x: Decimal) -> Self

Converts to this type from the input type.
Source§

impl From<IndexMap<String, Value>> for Value

Source§

fn from(x: Map) -> Self

Converts to this type from the input type.
Source§

impl From<Keypair> for Value

Source§

fn from(x: Keypair) -> Self

Converts to this type from the input type.
Source§

impl From<Pubkey> for Value

Source§

fn from(x: Pubkey) -> Self

Converts to this type from the input type.
Source§

impl From<Signature> for Value

Source§

fn from(x: Signature) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Value

Source§

fn from(x: String) -> Self

Converts to this type from the input type.
Source§

impl From<Value> for Value

Source§

fn from(value: Value) -> Self

Converts to this type from the input type.
Source§

impl From<Value> for Value

Source§

fn from(value: Value) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<Value>> for Value

Source§

fn from(x: Vec<Value>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for Value

Source§

fn from(x: Vec<u8>) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for Value

Source§

fn from(x: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for Value

Source§

fn from(x: f32) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Value

Source§

fn from(x: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i128> for Value

Source§

fn from(x: i128) -> Self

Converts to this type from the input type.
Source§

impl From<i16> for Value

Source§

fn from(x: i16) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Value

Source§

fn from(x: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Value

Source§

fn from(x: i64) -> Self

Converts to this type from the input type.
Source§

impl From<i8> for Value

Source§

fn from(x: i8) -> Self

Converts to this type from the input type.
Source§

impl From<u128> for Value

Source§

fn from(x: u128) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for Value

Source§

fn from(x: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for Value

Source§

fn from(x: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for Value

Source§

fn from(x: u64) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for Value

Source§

fn from(x: u8) -> Self

Converts to this type from the input type.
Source§

impl IntoDeserializer<'_, Error> for Value

Source§

type Deserializer = Value

The type of the deserializer being converted into.
Source§

fn into_deserializer(self) -> Self::Deserializer

Convert this value into a deserializer.
Source§

impl JsonSchema for Value

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(_: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

impl PartialEq for Value

Source§

fn eq(&self, other: &Value) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Value

Source§

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

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

impl TryFrom<Value> for u8

Source§

type Error = Value

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl StructuralPartialEq for Value

Auto Trait Implementations§

§

impl !Freeze for Value

§

impl RefUnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnwindSafe for Value

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,