Struct Value

Source
pub struct Value<T = ()> {
    pub value: ValueDef<T>,
    pub context: T,
}
Expand description

Value holds a representation of some value that has been decoded, as well as some arbitrary context.

Not all SCALE encoded types have an similar-named value; for instance, the values corresponding to sequence, array and composite types can all be represented with Composite. Only enough information is preserved here to to be able to encode and decode SCALE bytes with a known type to and from Values losslessly.

Fields§

§value: ValueDef<T>

The shape and associated data for this Value

§context: T

Some additional arbitrary context that can be associated with a value.

Implementations§

Source§

impl Value<()>

Source

pub fn named_composite<S, Vals>(vals: Vals) -> Self
where S: Into<String>, Vals: IntoIterator<Item = (S, Value<()>)>,

Construct a named composite type from any type which produces a tuple of keys and values when iterated over.

Source

pub fn unnamed_composite<Vals>(vals: Vals) -> Self
where Vals: IntoIterator<Item = Value<()>>,

Construct an unnamed composite type from any type which produces values when iterated over.

Source

pub fn variant<S: Into<String>>(name: S, values: Composite<()>) -> Value<()>

Create a new variant value without additional context.

Source

pub fn named_variant<S, F, Vals>(name: S, fields: Vals) -> Value<()>
where S: Into<String>, F: Into<String>, Vals: IntoIterator<Item = (F, Value<()>)>,

Create a new variant value with named fields and without additional context.

Source

pub fn unnamed_variant<S, Vals>(name: S, fields: Vals) -> Value<()>
where S: Into<String>, Vals: IntoIterator<Item = Value<()>>,

Create a new variant value with tuple-like fields and without additional context.

Source

pub fn bit_sequence(bits: BitSequence) -> Value<()>

Create a new bit sequence value without additional context.

Source

pub fn primitive(primitive: Primitive) -> Value<()>

Create a new primitive value without additional context.

Source

pub fn string<S: Into<String>>(val: S) -> Value<()>

Create a new string value without additional context.

Source

pub fn bool(val: bool) -> Value<()>

Create a new boolean value without additional context.

Source

pub fn char(val: char) -> Value<()>

Create a new char without additional context.

Source

pub fn u128(val: u128) -> Value<()>

Create a new unsigned integer without additional context.

Source

pub fn i128(val: i128) -> Value<()>

Create a new signed integer without additional context.

Source

pub fn from_bytes(bytes: impl AsRef<[u8]>) -> Value<()>

Create a new Value from a set of bytes; useful for converting things like AccountIds.

Source§

impl Value<()>

Source

pub fn without_context(value: ValueDef<()>) -> Value<()>

Create a new value with no associated context.

Source§

impl<T> Value<T>

Source

pub fn with_context(value: ValueDef<T>, context: T) -> Value<T>

Create a new value with some associated context.

Source

pub fn remove_context(self) -> Value<()>

Remove the context.

Source

pub fn map_context<F, U>(self, f: F) -> Value<U>
where F: Clone + FnMut(T) -> U,

Map the context to some different type.

Source

pub fn as_bool(&self) -> Option<bool>

If the value is a boolean value, return it.

Source

pub fn as_char(&self) -> Option<char>

If the value is a char, return it.

Source

pub fn as_u128(&self) -> Option<u128>

If the value is a u128, return it.

Source

pub fn as_i128(&self) -> Option<i128>

If the value is an i128, return it.

Source

pub fn as_str(&self) -> Option<&str>

If the value is a string, return it.

Trait Implementations§

Source§

impl<Ctx> At<Ctx> for Value<Ctx>

Source§

fn at<L: AsLocation>(&self, loc: L) -> Option<&Value<Ctx>>

Index into a value, returning a reference to the value if one exists, or None if not.
Source§

impl<T: Clone> Clone for Value<T>

Source§

fn clone(&self) -> Value<T>

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<T: Debug> Debug for Value<T>

Source§

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

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

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

Source§

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

Deserialize this value from the given Serde deserializer. Read more
Source§

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

Source§

type Error = DeserializerError

The error type that can be returned if some error occurs during deserialization.
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_bool<V>(self, visitor: V) -> Result<V::Value, Self::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::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::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::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::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::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::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::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::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::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::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::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::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::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::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::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_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_option<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

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

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

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

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

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

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

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

fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, Self::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::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§

fn deserialize_unit_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 unit struct with a particular name.
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_tuple<V>( self, len: usize, visitor: V, ) -> Result<V::Value, Self::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::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_struct<V>( self, name: &'static str, fields: &'static [&'static str], visitor: V, ) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

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

fn deserialize_enum<V>( self, name: &'static str, variants: &'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 is_human_readable(&self) -> bool

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

impl<T> Display for Value<T>

Source§

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

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

impl<T> EncodeAsFields for Value<T>

Source§

fn encode_as_fields_to<R: TypeResolver>( &self, fields: &mut dyn FieldIter<'_, R::TypeId>, types: &R, out: &mut Vec<u8>, ) -> Result<(), Error>

Given some fields describing the shape of a type, attempt to encode to that shape.
Source§

fn encode_as_fields<R>( &self, fields: &mut dyn FieldIter<'_, <R as TypeResolver>::TypeId, Item = Field<'_, <R as TypeResolver>::TypeId>>, types: &R, ) -> Result<Vec<u8>, Error>
where R: TypeResolver,

This is a helper function which internally calls EncodeAsFields::encode_as_fields_to. Prefer to implement that instead.
Source§

impl<T> EncodeAsType for Value<T>

Source§

fn encode_as_type_to<R: TypeResolver>( &self, type_id: R::TypeId, types: &R, out: &mut Vec<u8>, ) -> Result<(), Error>

Given some type_id, types, a context and some output target for the SCALE encoded bytes, attempt to SCALE encode the current value into the type given by type_id.
Source§

fn encode_as_type<R>( &self, type_id: <R as TypeResolver>::TypeId, types: &R, ) -> Result<Vec<u8>, Error>
where R: TypeResolver,

This is a helper function which internally calls EncodeAsType::encode_as_type_to. Prefer to implement that instead.
Source§

impl From<&str> for Value<()>

Source§

fn from(val: &str) -> Self

Converts to this type from the input type.
Source§

impl From<Bits> for Value<()>

Source§

fn from(val: BitSequence) -> Self

Converts to this type from the input type.
Source§

impl From<Composite<()>> for Value<()>

Source§

fn from(val: Composite<()>) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Value<()>

Source§

fn from(val: String) -> Self

Converts to this type from the input type.
Source§

impl From<Variant<()>> for Value<()>

Source§

fn from(val: Variant<()>) -> Self

Converts to this type from the input type.
Source§

impl<K: Into<String>, V: Into<Value<()>>> From<Vec<(K, V)>> for Value<()>

Source§

fn from(vals: Vec<(K, V)>) -> Self

Converts to this type from the input type.
Source§

impl<V: Into<Value<()>>> From<Vec<V>> for Value<()>

Source§

fn from(vals: Vec<V>) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for Value<()>

Source§

fn from(val: bool) -> Self

Converts to this type from the input type.
Source§

impl From<char> for Value<()>

Source§

fn from(val: char) -> Self

Converts to this type from the input type.
Source§

impl From<i128> for Value<()>

Source§

fn from(val: i128) -> Self

Converts to this type from the input type.
Source§

impl From<i16> for Value<()>

Source§

fn from(val: i16) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Value<()>

Source§

fn from(val: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Value<()>

Source§

fn from(val: i64) -> Self

Converts to this type from the input type.
Source§

impl From<i8> for Value<()>

Source§

fn from(val: i8) -> Self

Converts to this type from the input type.
Source§

impl From<isize> for Value<()>

Source§

fn from(val: isize) -> Self

Converts to this type from the input type.
Source§

impl From<u128> for Value<()>

Source§

fn from(val: u128) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for Value<()>

Source§

fn from(val: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for Value<()>

Source§

fn from(val: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for Value<()>

Source§

fn from(val: u64) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for Value<()>

Source§

fn from(val: u8) -> Self

Converts to this type from the input type.
Source§

impl From<usize> for Value<()>

Source§

fn from(val: usize) -> Self

Converts to this type from the input type.
Source§

impl<'de, T> IntoDeserializer<'de, DeserializerError> for Value<T>

Source§

type Deserializer = Value<T>

The type of the deserializer being converted into.
Source§

fn into_deserializer(self) -> Self::Deserializer

Convert this value into a deserializer.
Source§

impl IntoVisitor for Value<()>

Source§

type AnyVisitor<R: TypeResolver> = VisitorWithCrateError<DecodeValueVisitor<R, EmptyContext>>

The visitor type used to decode SCALE encoded bytes to Self.
Source§

fn into_visitor<R: TypeResolver>() -> Self::AnyVisitor<R>

A means of obtaining this visitor.
Source§

impl<T: PartialEq> PartialEq for Value<T>

Source§

fn eq(&self, other: &Value<T>) -> 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<T> Serialize for Value<T>

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<T: Eq> Eq for Value<T>

Source§

impl<T> StructuralPartialEq for Value<T>

Auto Trait Implementations§

§

impl<T> Freeze for Value<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Value<T>
where T: RefUnwindSafe,

§

impl<T> Send for Value<T>
where T: Send,

§

impl<T> Sync for Value<T>
where T: Sync,

§

impl<T> Unpin for Value<T>
where T: Unpin,

§

impl<T> UnwindSafe for Value<T>
where T: UnwindSafe,

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> DecodeAsType for T
where T: IntoVisitor,

Source§

fn decode_as_type_maybe_compact<R>( input: &mut &[u8], type_id: <R as TypeResolver>::TypeId, types: &R, is_compact: bool, ) -> Result<T, Error>
where R: TypeResolver,

Source§

fn decode_as_type<R>( input: &mut &[u8], type_id: <R as TypeResolver>::TypeId, types: &R, ) -> Result<Self, Error>
where R: TypeResolver,

Given some input bytes, a type_id, and type registry, attempt to decode said bytes into Self. Implementations should modify the &mut reference to the bytes such that any bytes not used in the course of decoding are still pointed to after decoding is complete.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> JsonSchemaMaybe for T