Enum multiversx_sc::types::SCResult
source · pub enum SCResult<T, E = StaticSCError> {
Ok(T),
Err(E),
}
Expand description
Default way to optionally return an error from a smart contract endpoint.
Variants§
Implementations§
source§impl<T, E> SCResult<T, E>
impl<T, E> SCResult<T, E>
pub fn is_ok(&self) -> bool
pub fn is_err(&self) -> bool
pub fn ok(self) -> Option<T>
pub fn err(self) -> Option<E>
sourcepub fn unwrap_or_signal_error<FA: EndpointFinishApi>(self) -> Twhere
E: SCError,
pub fn unwrap_or_signal_error<FA: EndpointFinishApi>(self) -> Twhere E: SCError,
Returns the contained Ok value or signals the error and exits.
sourcepub fn from_result<FromErr>(r: Result<T, FromErr>) -> Selfwhere
FromErr: Into<E>,
pub fn from_result<FromErr>(r: Result<T, FromErr>) -> Selfwhere FromErr: Into<E>,
Used to convert from a regular Rust result.
Any error type is accepted as long as it can be converted to a SCError
(Vec<u8>
, &[u8]
, BoxedBytes
, String
, &str
are covered).
Trait Implementations§
source§impl<T> From<SCResult<T, StaticSCError>> for Result<T, StaticSCError>
impl<T> From<SCResult<T, StaticSCError>> for Result<T, StaticSCError>
source§impl<T, E> FromResidual<<SCResult<T, E> as Try>::Residual> for SCResult<T, E>
impl<T, E> FromResidual<<SCResult<T, E> as Try>::Residual> for SCResult<T, E>
source§fn from_residual(r: E) -> Self
fn from_residual(r: E) -> Self
🔬This is a nightly-only experimental API. (
try_trait_v2
)Constructs the type from a compatible
Residual
type. Read moresource§impl<T, FromErr> FromResidual<Result<Infallible, FromErr>> for SCResult<T>where
FromErr: Into<StaticSCError>,
impl<T, FromErr> FromResidual<Result<Infallible, FromErr>> for SCResult<T>where FromErr: Into<StaticSCError>,
source§fn from_residual(residual: Result<Infallible, FromErr>) -> Self
fn from_residual(residual: Result<Infallible, FromErr>) -> Self
🔬This is a nightly-only experimental API. (
try_trait_v2
)Constructs the type from a compatible
Residual
type. Read moresource§impl<T: PartialEq, E: PartialEq> PartialEq<SCResult<T, E>> for SCResult<T, E>
impl<T: PartialEq, E: PartialEq> PartialEq<SCResult<T, E>> for SCResult<T, E>
source§impl<T, E> TopEncodeMulti for SCResult<T, E>where
T: TopEncodeMulti,
E: TopEncodeMulti,
impl<T, E> TopEncodeMulti for SCResult<T, E>where T: TopEncodeMulti, E: TopEncodeMulti,
source§fn multi_encode_or_handle_err<O, H>(
&self,
output: &mut O,
h: H
) -> Result<(), H::HandledErr>where
O: TopEncodeMultiOutput,
H: EncodeErrorHandler,
fn multi_encode_or_handle_err<O, H>( &self, output: &mut O, h: H ) -> Result<(), H::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.
source§impl<T, E> Try for SCResult<T, E>
impl<T, E> Try for SCResult<T, E>
Implementing the Try
trait overloads the ?
operator.
Documentation on the new version of the trait:
https://github.com/scottmcm/rfcs/blob/do-or-do-not/text/0000-try-trait-v2.md#the-try-trait
§type Output = T
type Output = T
🔬This is a nightly-only experimental API. (
try_trait_v2
)The type of the value produced by
?
when not short-circuiting.§type Residual = E
type Residual = E
🔬This is a nightly-only experimental API. (
try_trait_v2
)The type of the value passed to
FromResidual::from_residual
as part of ?
when short-circuiting. Read moresource§fn branch(self) -> ControlFlow<Self::Residual, T>
fn branch(self) -> ControlFlow<Self::Residual, T>
🔬This is a nightly-only experimental API. (
try_trait_v2
)Used in
?
to decide whether the operator should produce a value
(because this returned ControlFlow::Continue
)
or propagate a value back to the caller
(because this returned ControlFlow::Break
). Read moresource§fn from_output(v: T) -> Self
fn from_output(v: T) -> Self
🔬This is a nightly-only experimental API. (
try_trait_v2
)Constructs the type from its
Output
type. Read moresource§impl<T: TypeAbi, E> TypeAbi for SCResult<T, E>
impl<T: TypeAbi, E> TypeAbi for SCResult<T, E>
fn type_name() -> TypeName
source§fn provide_type_descriptions<TDC: TypeDescriptionContainer>(
accumulator: &mut TDC
)
fn provide_type_descriptions<TDC: TypeDescriptionContainer>( accumulator: &mut TDC )
A type can provide more than its own description.
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.
impl<T: Eq, E: Eq> Eq for SCResult<T, E>
impl<T, E> StructuralEq for SCResult<T, E>
impl<T, E> StructuralPartialEq for SCResult<T, E>
Auto Trait Implementations§
impl<T, E> CodecFromSelf for SCResult<T, E>where E: CodecFromSelf, T: CodecFromSelf,
impl<T, E> RefUnwindSafe for SCResult<T, E>where E: RefUnwindSafe, T: RefUnwindSafe,
impl<T, E> Send for SCResult<T, E>where E: Send, T: Send,
impl<T, E> Sync for SCResult<T, E>where E: Sync, T: Sync,
impl<T, E> Unpin for SCResult<T, E>where E: Unpin, T: Unpin,
impl<T, E> UnwindSafe for SCResult<T, E>where E: UnwindSafe, 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