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§

§

Ok(T)

§

Err(E)

Implementations§

source§

impl<T, E> SCResult<T, E>

source

pub fn is_ok(&self) -> bool

source

pub fn is_err(&self) -> bool

source

pub fn ok(self) -> Option<T>

source

pub fn err(self) -> Option<E>

source

pub fn unwrap_or_signal_error<FA: EndpointFinishApi>(self) -> Twhere E: SCError,

Returns the contained Ok value or signals the error and exits.

source

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).

source§

impl<T> SCResult<T>

source

pub fn unwrap(self) -> T

Trait Implementations§

source§

impl<T: Clone, E: Clone> Clone for SCResult<T, E>

source§

fn clone(&self) -> SCResult<T, E>

Returns a copy 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, E: Debug> Debug for SCResult<T, E>

source§

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

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

impl<T, Err> From<Result<T, Err>> for SCResult<T>where Err: Into<StaticSCError>,

source§

fn from(result: Result<T, Err>) -> Self

Converts to this type from the input type.
source§

impl<T> From<SCResult<T, StaticSCError>> for Result<T, StaticSCError>

source§

fn from(result: SCResult<T>) -> Self

Converts to this type from the input type.
source§

impl<T, E> FromResidual<<SCResult<T, E> as Try>::Residual> for SCResult<T, E>

source§

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 more
source§

impl<T, FromErr> FromResidual<Result<Infallible, FromErr>> for SCResult<T>where FromErr: Into<StaticSCError>,

source§

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 more
source§

impl<T: PartialEq, E: PartialEq> PartialEq<SCResult<T, E>> for SCResult<T, E>

source§

fn eq(&self, other: &SCResult<T, E>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

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,

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,

Attempt to serialize the value to ouput.
source§

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

🔬This is a nightly-only experimental API. (try_trait_v2)
The type of the value produced by ? when not short-circuiting.
§

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 more
source§

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 more
source§

fn from_output(v: T) -> Self

🔬This is a nightly-only experimental API. (try_trait_v2)
Constructs the type from its Output type. Read more
source§

impl<T: TypeAbi, E> TypeAbi for SCResult<T, E>

source§

fn type_name() -> TypeName

source§

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.
source§

impl<T: Eq, E: Eq> Eq for SCResult<T, E>

source§

impl<T, E> StructuralEq for SCResult<T, E>

source§

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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> ToOwned for Twhere T: Clone,

§

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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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<F, I> CodecInto<F> for Iwhere I: TopEncodeMulti, F: CodecFrom<I>,