pub struct WrapperKeepOpaque<T> { /* private fields */ }Expand description
A wrapper for any type T which implement encode/decode in a way compatible with Vec<u8>.
WrapperKeepOpaque stores the type only in its opaque format, aka as a Vec<u8>. To
access the real type T Self::try_decode needs to be used.
Implementations§
Source§impl<T> WrapperKeepOpaque<T>
impl<T> WrapperKeepOpaque<T>
Sourcepub fn try_decode(&self) -> Option<T>where
T: Decode,
pub fn try_decode(&self) -> Option<T>where
T: Decode,
Try to decode the wrapped type from the inner data.
Returns None if the decoding failed.
Sourcepub fn encoded_len(&self) -> usize
pub fn encoded_len(&self) -> usize
Returns the length of the encoded T.
Sourcepub fn from_encoded(data: Vec<u8>) -> Self
pub fn from_encoded(data: Vec<u8>) -> Self
Create from the given encoded data.
Sourcepub fn from_value(value: T) -> Selfwhere
T: Encode,
pub fn from_value(value: T) -> Selfwhere
T: Encode,
Create from some raw value by encoding it.
Trait Implementations§
Source§impl<T> Clone for WrapperKeepOpaque<T>
impl<T> Clone for WrapperKeepOpaque<T>
Source§impl<T> Debug for WrapperKeepOpaque<T>
impl<T> Debug for WrapperKeepOpaque<T>
Source§impl<T> Decode for WrapperKeepOpaque<T>where
PhantomDataSendSync<T>: Decode,
impl<T> Decode for WrapperKeepOpaque<T>where
PhantomDataSendSync<T>: Decode,
Source§fn decode<__CodecInputEdqy: Input>(
__codec_input_edqy: &mut __CodecInputEdqy,
) -> Result<Self, Error>
fn decode<__CodecInputEdqy: Input>( __codec_input_edqy: &mut __CodecInputEdqy, ) -> Result<Self, Error>
Attempt to deserialise the value from input.
Source§fn decode_into<I>(
input: &mut I,
dst: &mut MaybeUninit<Self>,
) -> Result<DecodeFinished, Error>where
I: Input,
fn decode_into<I>(
input: &mut I,
dst: &mut MaybeUninit<Self>,
) -> Result<DecodeFinished, Error>where
I: Input,
Attempt to deserialize the value from input into a pre-allocated piece of memory. Read more
Source§impl<T> Default for WrapperKeepOpaque<T>
impl<T> Default for WrapperKeepOpaque<T>
Source§impl<T> Encode for WrapperKeepOpaque<T>where
PhantomDataSendSync<T>: Encode,
impl<T> Encode for WrapperKeepOpaque<T>where
PhantomDataSendSync<T>: Encode,
Source§fn size_hint(&self) -> usize
fn size_hint(&self) -> usize
If possible give a hint of expected size of the encoding. Read more
Source§fn encode_to<__CodecOutputEdqy: Output + ?Sized>(
&self,
__codec_dest_edqy: &mut __CodecOutputEdqy,
)
fn encode_to<__CodecOutputEdqy: Output + ?Sized>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy, )
Convert self to a slice and append it to the destination.
Source§fn using_encoded<R, F>(&self, f: F) -> R
fn using_encoded<R, F>(&self, f: F) -> R
Convert self to a slice and then invoke the given closure with it.
Source§fn encoded_size(&self) -> usize
fn encoded_size(&self) -> usize
Calculates the encoded size. Read more
Source§impl<T> EncodeAsType for WrapperKeepOpaque<T>
impl<T> EncodeAsType for WrapperKeepOpaque<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>
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,
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<T> Hash for WrapperKeepOpaque<T>
impl<T> Hash for WrapperKeepOpaque<T>
Source§impl<T> IntoVisitor for WrapperKeepOpaque<T>
impl<T> IntoVisitor for WrapperKeepOpaque<T>
Source§type AnyVisitor<R: TypeResolver> = WrapperKeepOpaqueVisitor<T, R>
type AnyVisitor<R: TypeResolver> = WrapperKeepOpaqueVisitor<T, R>
The visitor type used to decode SCALE encoded bytes to
Self.Source§fn into_visitor<R: TypeResolver>() -> WrapperKeepOpaqueVisitor<T, R>
fn into_visitor<R: TypeResolver>() -> WrapperKeepOpaqueVisitor<T, R>
A means of obtaining this visitor.
Source§impl<T> PartialEq for WrapperKeepOpaque<T>
impl<T> PartialEq for WrapperKeepOpaque<T>
impl<T> EncodeLike for WrapperKeepOpaque<T>where
PhantomDataSendSync<T>: Encode,
impl<T> Eq for WrapperKeepOpaque<T>
Auto Trait Implementations§
impl<T> Freeze for WrapperKeepOpaque<T>
impl<T> RefUnwindSafe for WrapperKeepOpaque<T>where
T: RefUnwindSafe,
impl<T> Send for WrapperKeepOpaque<T>
impl<T> Sync for WrapperKeepOpaque<T>
impl<T> Unpin for WrapperKeepOpaque<T>where
T: Unpin,
impl<T> UnsafeUnpin for WrapperKeepOpaque<T>
impl<T> UnwindSafe for WrapperKeepOpaque<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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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,
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> DecodeLimit for Twhere
T: Decode,
impl<T> DecodeLimit for Twhere
T: Decode,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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