Struct scale_value::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 Value
s
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<()>
impl Value<()>
sourcepub fn named_composite<S, Vals>(vals: Vals) -> Self
pub fn named_composite<S, Vals>(vals: Vals) -> Self
Construct a named composite type from any type which produces a tuple of keys and values when iterated over.
sourcepub fn unnamed_composite<Vals>(vals: Vals) -> Self
pub fn unnamed_composite<Vals>(vals: Vals) -> Self
Construct an unnamed composite type from any type which produces values when iterated over.
sourcepub fn variant<S: Into<String>>(name: S, values: Composite<()>) -> Value<()>
pub fn variant<S: Into<String>>(name: S, values: Composite<()>) -> Value<()>
Create a new variant value without additional context.
sourcepub fn named_variant<S, F, Vals>(name: S, fields: Vals) -> Value<()>
pub fn named_variant<S, F, Vals>(name: S, fields: Vals) -> Value<()>
Create a new variant value with named fields and without additional context.
sourcepub fn unnamed_variant<S, Vals>(name: S, fields: Vals) -> Value<()>
pub fn unnamed_variant<S, Vals>(name: S, fields: Vals) -> Value<()>
Create a new variant value with tuple-like fields and without additional context.
sourcepub fn bit_sequence(bits: BitSequence) -> Value<()>
pub fn bit_sequence(bits: BitSequence) -> Value<()>
Create a new bit sequence value without additional context.
sourcepub fn primitive(primitive: Primitive) -> Value<()>
pub fn primitive(primitive: Primitive) -> Value<()>
Create a new primitive value without additional context.
source§impl<T> Value<T>
impl<T> Value<T>
sourcepub fn with_context(value: ValueDef<T>, context: T) -> Value<T>
pub fn with_context(value: ValueDef<T>, context: T) -> Value<T>
Create a new value with some associated context.
sourcepub fn remove_context(self) -> Value<()>
pub fn remove_context(self) -> Value<()>
Remove the context.
sourcepub fn map_context<F, U>(self, f: F) -> Value<U>
pub fn map_context<F, U>(self, f: F) -> Value<U>
Map the context to some different type.
Trait Implementations§
source§impl<'de> Deserialize<'de> for Value<()>
impl<'de> Deserialize<'de> for Value<()>
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
source§impl<'de, T> Deserializer<'de> for Value<T>
impl<'de, T> Deserializer<'de> for Value<T>
§type Error = DeserializerError
type Error = DeserializerError
source§fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserializer
to figure out how to drive the visitor based
on what data type is in the input. Read moresource§fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a bool
value.source§fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting an i8
value.source§fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting an i16
value.source§fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting an i32
value.source§fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting an i64
value.source§fn deserialize_i128<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_i128<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
source§fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a u8
value.source§fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a u16
value.source§fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a u32
value.source§fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a u64
value.source§fn deserialize_u128<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_u128<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
source§fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a f32
value.source§fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a f64
value.source§fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a char
value.source§fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a string value and does
not benefit from taking ownership of buffered data owned by the
Deserializer
. Read moresource§fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a string value and would
benefit from taking ownership of buffered data owned by the
Deserializer
. Read moresource§fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a byte array and does not
benefit from taking ownership of buffered data owned by the
Deserializer
. Read moresource§fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a byte array and would
benefit from taking ownership of buffered data owned by the
Deserializer
. Read moresource§fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting an optional value. Read moresource§fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a unit value.source§fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
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>,
fn deserialize_map<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
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>,
fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
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>,
fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type needs to deserialize a value whose type
doesn’t matter because it is ignored. Read moresource§fn deserialize_unit_struct<V>(
self,
name: &'static str,
visitor: V
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_unit_struct<V>(
self,
name: &'static str,
visitor: V
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
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>,
fn deserialize_newtype_struct<V>(
self,
name: &'static str,
visitor: V
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
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>,
fn deserialize_tuple<V>(
self,
len: usize,
visitor: V
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
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>,
fn deserialize_tuple_struct<V>(
self,
name: &'static str,
len: usize,
visitor: V
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
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>,
fn deserialize_struct<V>(
self,
name: &'static str,
fields: &'static [&'static str],
visitor: V
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
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>,
fn deserialize_enum<V>(
self,
name: &'static str,
variants: &'static [&'static str],
visitor: V
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting an enum value with a
particular name and possible variants.source§fn is_human_readable(&self) -> bool
fn is_human_readable(&self) -> bool
Deserialize
implementations should expect to
deserialize their human-readable form. Read moresource§impl<T> EncodeAsFields for Value<T>
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>
fn encode_as_fields_to<R: TypeResolver>( &self, fields: &mut dyn FieldIter<'_, R::TypeId>, types: &R, out: &mut Vec<u8> ) -> Result<(), Error>
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,
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,
EncodeAsFields::encode_as_fields_to
. Prefer to
implement that instead.source§impl<T> EncodeAsType for Value<T>
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>
fn encode_as_type_to<R: TypeResolver>( &self, type_id: &R::TypeId, types: &R, out: &mut Vec<u8> ) -> Result<(), Error>
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,
fn encode_as_type<R>(
&self,
type_id: &<R as TypeResolver>::TypeId,
types: &R
) -> Result<Vec<u8>, Error>where
R: TypeResolver,
EncodeAsType::encode_as_type_to
. Prefer to
implement that instead.source§impl From<Bits> for Value<()>
impl From<Bits> for Value<()>
source§fn from(val: BitSequence) -> Self
fn from(val: BitSequence) -> Self
source§impl<'de, T> IntoDeserializer<'de, DeserializerError> for Value<T>
impl<'de, T> IntoDeserializer<'de, DeserializerError> for Value<T>
§type Deserializer = Value<T>
type Deserializer = Value<T>
source§fn into_deserializer(self) -> Self::Deserializer
fn into_deserializer(self) -> Self::Deserializer
source§impl IntoVisitor for Value<()>
impl IntoVisitor for Value<()>
§type AnyVisitor<R: TypeResolver> = VisitorWithCrateError<DecodeValueVisitor<R, (), DefaultMapper>>
type AnyVisitor<R: TypeResolver> = VisitorWithCrateError<DecodeValueVisitor<R, (), DefaultMapper>>
Self
.source§fn into_visitor<R: TypeResolver>() -> Self::AnyVisitor<R>
fn into_visitor<R: TypeResolver>() -> Self::AnyVisitor<R>
source§impl<T: PartialEq> PartialEq for Value<T>
impl<T: PartialEq> PartialEq for Value<T>
impl<T: Eq> Eq for Value<T>
impl<T> StructuralPartialEq for Value<T>
Auto Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> DecodeAsType for Twhere
T: IntoVisitor,
impl<T> DecodeAsType for Twhere
T: IntoVisitor,
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,
fn decode_as_type<R>(
input: &mut &[u8],
type_id: &<R as TypeResolver>::TypeId,
types: &R
) -> Result<Self, Error>where
R: TypeResolver,
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.