pub struct ManagedOption<M, T>where
M: ManagedTypeApi,
T: ManagedType<M>,{ /* private fields */ }
Expand description
A very efficient optional managed type.
None
is flagged by a special invalid handle.
Implementations§
Source§impl<M, T> ManagedOption<M, T>where
M: ManagedTypeApi,
T: ManagedType<M>,
impl<M, T> ManagedOption<M, T>where
M: ManagedTypeApi,
T: ManagedType<M>,
pub fn some(value: T) -> ManagedOption<M, T>
pub fn none() -> ManagedOption<M, T>
Source§impl<M, T> ManagedOption<M, T>where
M: ManagedTypeApi,
T: ManagedType<M>,
impl<M, T> ManagedOption<M, T>where
M: ManagedTypeApi,
T: ManagedType<M>,
pub fn is_none(&self) -> bool
pub fn is_some(&self) -> bool
Sourcepub unsafe fn unwrap_no_check(self) -> T
pub unsafe fn unwrap_no_check(self) -> T
Assumes that value is Some and unwraps without checking.
§Safety
Must always be called under an if
checking .is_some()
, otherwise will lead to undefined behaviour.
pub fn into_option(self) -> Option<T>
pub fn as_option(&self) -> Option<ManagedRef<'_, M, T>>
pub fn unwrap_or_else<F>(self, f: F) -> Twhere
F: Fn() -> T,
pub fn unwrap_or_sc_panic(self, panic_message: &str) -> T
pub fn map<U, F>(self, f: F) -> ManagedOption<M, U>where
U: ManagedType<M>,
F: FnOnce(T) -> U,
pub fn map_or_else<Context, D, F, R>( self, context: Context, default: D, f: F, ) -> R
pub fn map_ref_or_else<Context, D, F, R>( &self, context: Context, default: D, f: F, ) -> R
Trait Implementations§
Source§impl<M, T> Clone for ManagedOption<M, T>
impl<M, T> Clone for ManagedOption<M, T>
Source§fn clone(&self) -> ManagedOption<M, T>
fn clone(&self) -> ManagedOption<M, T>
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<M, T> Debug for ManagedOption<M, T>
impl<M, T> Debug for ManagedOption<M, T>
Source§impl<M, T> From<Option<T>> for ManagedOption<M, T>where
M: ManagedTypeApi,
T: ManagedType<M>,
impl<M, T> From<Option<T>> for ManagedOption<M, T>where
M: ManagedTypeApi,
T: ManagedType<M>,
Source§fn from(opt: Option<T>) -> ManagedOption<M, T>
fn from(opt: Option<T>) -> ManagedOption<M, T>
Converts to this type from the input type.
Source§impl<M, T> ManagedVecItem for ManagedOption<M, T>where
M: ManagedTypeApi,
T: ManagedType<M> + 'static,
impl<M, T> ManagedVecItem for ManagedOption<M, T>where
M: ManagedTypeApi,
T: ManagedType<M> + 'static,
Source§const SKIPS_RESERIALIZATION: bool = false
const SKIPS_RESERIALIZATION: bool = false
If true, then the encoding of the item is identical to the payload,
and no further conversion is necessary
(the underlying buffer can be used as-is during serialization).
False for all managed types, but true for basic types (like
u32
).Source§type PAYLOAD = ManagedVecItemPayloadBuffer<4>
type PAYLOAD = ManagedVecItemPayloadBuffer<4>
Type managing the underlying binary representation in a ManagedVec..
Source§type Ref<'a> = ManagedOption<M, T>
type Ref<'a> = ManagedOption<M, T>
Reference representation of the ManagedVec item. Read more
Source§fn read_from_payload(
payload: &<ManagedOption<M, T> as ManagedVecItem>::PAYLOAD,
) -> ManagedOption<M, T>
fn read_from_payload( payload: &<ManagedOption<M, T> as ManagedVecItem>::PAYLOAD, ) -> ManagedOption<M, T>
Parses given bytes as a an owned object.
Source§unsafe fn borrow_from_payload<'a>(
payload: &<ManagedOption<M, T> as ManagedVecItem>::PAYLOAD,
) -> <ManagedOption<M, T> as ManagedVecItem>::Ref<'a>
unsafe fn borrow_from_payload<'a>( payload: &<ManagedOption<M, T> as ManagedVecItem>::PAYLOAD, ) -> <ManagedOption<M, T> as ManagedVecItem>::Ref<'a>
Parses given bytes as a representation of the object, either owned, or a reference. Read more
Source§fn save_to_payload(
self,
payload: &mut <ManagedOption<M, T> as ManagedVecItem>::PAYLOAD,
)
fn save_to_payload( self, payload: &mut <ManagedOption<M, T> as ManagedVecItem>::PAYLOAD, )
Converts the object into bytes. Read more
fn payload_size() -> usize
Source§impl<M, T> NestedDecode for ManagedOption<M, T>
impl<M, T> NestedDecode for ManagedOption<M, T>
Source§fn dep_decode_or_handle_err<I, H>(
input: &mut I,
h: H,
) -> Result<ManagedOption<M, T>, <H as DecodeErrorHandler>::HandledErr>where
I: NestedDecodeInput,
H: DecodeErrorHandler,
fn dep_decode_or_handle_err<I, H>(
input: &mut I,
h: H,
) -> Result<ManagedOption<M, T>, <H as DecodeErrorHandler>::HandledErr>where
I: NestedDecodeInput,
H: DecodeErrorHandler,
Version of
dep_decode
that can handle errors as soon as they occur.
For instance in can exit immediately and make sure that if it returns, it is a success.
By not deferring error handling, this can lead to somewhat smaller bytecode.Source§fn dep_decode<I>(input: &mut I) -> Result<Self, DecodeError>where
I: NestedDecodeInput,
fn dep_decode<I>(input: &mut I) -> Result<Self, DecodeError>where
I: NestedDecodeInput,
Attempt to deserialise the value from input,
using the format of an object nested inside another structure.
In case of success returns the deserialized value and the number of bytes consumed during the operation.
Source§impl<M, T> NestedEncode for ManagedOption<M, T>
impl<M, T> NestedEncode for ManagedOption<M, T>
Source§fn dep_encode_or_handle_err<O, H>(
&self,
dest: &mut O,
h: H,
) -> Result<(), <H as EncodeErrorHandler>::HandledErr>where
O: NestedEncodeOutput,
H: EncodeErrorHandler,
fn dep_encode_or_handle_err<O, H>(
&self,
dest: &mut O,
h: H,
) -> Result<(), <H as EncodeErrorHandler>::HandledErr>where
O: NestedEncodeOutput,
H: EncodeErrorHandler,
Version of
dep_encode
that can handle errors as soon as they occur.
For instance in can exit immediately and make sure that if it returns, it is a success.
By not deferring error handling, this can lead to somewhat smaller bytecode.Source§fn dep_encode<O>(&self, dest: &mut O) -> Result<(), EncodeError>where
O: NestedEncodeOutput,
fn dep_encode<O>(&self, dest: &mut O) -> Result<(), EncodeError>where
O: NestedEncodeOutput,
NestedEncode to output, using the format of an object nested inside another structure.
Does not provide compact version.
Source§impl<M, T> PartialEq for ManagedOption<M, T>
impl<M, T> PartialEq for ManagedOption<M, T>
Source§impl<M, T> TopDecode for ManagedOption<M, T>
impl<M, T> TopDecode for ManagedOption<M, T>
Source§fn top_decode_or_handle_err<I, H>(
input: I,
h: H,
) -> Result<ManagedOption<M, T>, <H as DecodeErrorHandler>::HandledErr>where
I: TopDecodeInput,
H: DecodeErrorHandler,
fn top_decode_or_handle_err<I, H>(
input: I,
h: H,
) -> Result<ManagedOption<M, T>, <H as DecodeErrorHandler>::HandledErr>where
I: TopDecodeInput,
H: DecodeErrorHandler,
Version of
top_decode
that can handle errors as soon as they occur.
For instance it can exit immediately and make sure that if it returns, it is a success.
By not deferring error handling, this can lead to somewhat smaller bytecode.Source§fn top_decode<I>(input: I) -> Result<Self, DecodeError>where
I: TopDecodeInput,
fn top_decode<I>(input: I) -> Result<Self, DecodeError>where
I: TopDecodeInput,
Attempt to deserialize the value from input.
Source§impl<M, T> TopEncode for ManagedOption<M, T>
impl<M, T> TopEncode for ManagedOption<M, T>
Source§fn top_encode_or_handle_err<O, H>(
&self,
output: O,
h: H,
) -> Result<(), <H as EncodeErrorHandler>::HandledErr>where
O: TopEncodeOutput,
H: EncodeErrorHandler,
fn top_encode_or_handle_err<O, H>(
&self,
output: O,
h: H,
) -> Result<(), <H as EncodeErrorHandler>::HandledErr>where
O: TopEncodeOutput,
H: EncodeErrorHandler,
Version of
top_encode
that can handle errors as soon as they occur.
For instance in can exit immediately and make sure that if it returns, it is a success.
By not deferring error handling, this can lead to somewhat smaller bytecode.Source§fn top_encode<O>(&self, output: O) -> Result<(), EncodeError>where
O: TopEncodeOutput,
fn top_encode<O>(&self, output: O) -> Result<(), EncodeError>where
O: TopEncodeOutput,
Attempt to serialize the value to ouput.
Source§impl<M, T> TypeAbi for ManagedOption<M, T>
impl<M, T> TypeAbi for ManagedOption<M, T>
type Unmanaged = Option<<T as TypeAbi>::Unmanaged>
fn type_name_rust() -> String
Source§fn provide_type_descriptions<TDC>(accumulator: &mut TDC)where
TDC: TypeDescriptionContainer,
fn provide_type_descriptions<TDC>(accumulator: &mut TDC)where
TDC: TypeDescriptionContainer,
A type can provide more than its own name.
For instance, a struct can also provide the descriptions of the type of its fields.
TypeAbi doesn’t care for the exact accumulator type,
which is abstracted by the TypeDescriptionContainer trait.
fn type_names() -> TypeNames
impl<M, T> Eq for ManagedOption<M, T>
impl<M, T, U> TypeAbiFrom<ManagedOption<M, U>> for ManagedOption<M, T>
impl<M, T, U> TypeAbiFrom<Option<U>> for ManagedOption<M, T>
Auto Trait Implementations§
impl<M, T> Freeze for ManagedOption<M, T>
impl<M, T> RefUnwindSafe for ManagedOption<M, T>
impl<M, T> Send for ManagedOption<M, T>
impl<M, T> Sync for ManagedOption<M, T>
impl<M, T> Unpin for ManagedOption<M, T>
impl<M, T> UnwindSafe for ManagedOption<M, T>
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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<T> InterpretableFrom<&T> for Twhere
T: Clone,
impl<T> InterpretableFrom<&T> for Twhere
T: Clone,
fn interpret_from(from: &T, _context: &InterpreterContext) -> T
Source§impl<T> InterpretableFrom<T> for T
impl<T> InterpretableFrom<T> for T
fn interpret_from(from: T, _context: &InterpreterContext) -> T
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 moreSource§impl<T> ReconstructableFrom<&T> for Twhere
T: Clone,
impl<T> ReconstructableFrom<&T> for Twhere
T: Clone,
fn reconstruct_from(from: &T, _builder: &ReconstructorContext) -> T
Source§impl<T> ReconstructableFrom<T> for T
impl<T> ReconstructableFrom<T> for T
fn reconstruct_from(from: T, _builder: &ReconstructorContext) -> T
Source§impl<T> SCCodec for Twhere
T: TopEncode,
impl<T> SCCodec for Twhere
T: TopEncode,
fn fmt<F>(&self, f: &mut F)where
F: FormatByteReceiver,
Source§impl<T> TopDecodeMulti for Twhere
T: TopDecode,
impl<T> TopDecodeMulti for Twhere
T: TopDecode,
Source§const IS_SINGLE_VALUE: bool = true
const IS_SINGLE_VALUE: bool = true
Used to optimize single value loading of endpoint arguments.
fn multi_decode_or_handle_err<I, H>(
input: &mut I,
h: H,
) -> Result<T, <H as DecodeErrorHandler>::HandledErr>where
I: TopDecodeMultiInput,
H: DecodeErrorHandler,
fn multi_decode<I>(input: &mut I) -> Result<Self, DecodeError>where
I: TopDecodeMultiInput,
Source§impl<T> TopDecodeMultiLength for T
impl<T> TopDecodeMultiLength for T
Source§impl<T> TopEncodeMulti for Twhere
T: TopEncode,
impl<T> TopEncodeMulti for Twhere
T: TopEncode,
Source§fn multi_encode_or_handle_err<O, H>(
&self,
output: &mut O,
h: H,
) -> Result<(), <H as EncodeErrorHandler>::HandledErr>where
O: TopEncodeMultiOutput,
H: EncodeErrorHandler,
fn multi_encode_or_handle_err<O, H>(
&self,
output: &mut O,
h: H,
) -> Result<(), <H as EncodeErrorHandler>::HandledErr>where
O: TopEncodeMultiOutput,
H: EncodeErrorHandler,
Version of
top_encode
that can handle errors as soon as they occur.
For instance in can exit immediately and make sure that if it returns, it is a success.
By not deferring error handling, this can lead to somewhat smaller bytecode.Source§fn multi_encode<O>(&self, output: &mut O) -> Result<(), EncodeError>where
O: TopEncodeMultiOutput,
fn multi_encode<O>(&self, output: &mut O) -> Result<(), EncodeError>where
O: TopEncodeMultiOutput,
Attempt to serialize the value to ouput.