Skip to main content

Envelope

Enum Envelope 

Source
pub enum Envelope<T> {
    Success {
        version: String,
        data: T,
    },
    Failure {
        version: String,
        error: OpError,
    },
}
Expand description

sc-ai-cli response envelope.

Success carries data and writes error as JSON null. Failure carries OpError and writes data as JSON null. Constructors stamp ENVELOPE_VERSION. Deserialization keeps the version string from the input. An ok flag that disagrees with the other field, or an object that does not have exactly the four keys, is rejected with DISCRIMINANT_CODE in the error.

Variants§

§

Success

ok is true and data is T.

Fields

§version: String

Contract version read or written for this value.

§data: T

Successful payload. JSON null is a valid T such as () or None.

§

Failure

ok is false and error is the operation error.

Fields

§version: String

Contract version read or written for this value.

§error: OpError

Operation error.

Implementations§

Source§

impl<T> Envelope<T>

Source

pub fn success(data: T) -> Self

Builds a success envelope at ENVELOPE_VERSION.

Source

pub fn failure(error: OpError) -> Self

Builds a failure envelope at ENVELOPE_VERSION.

Source

pub fn version(&self) -> &str

Contract version stored on this value.

Source

pub fn is_ok(&self) -> bool

Reports whether this value is the success case.

Source

pub fn data(&self) -> Option<&T>

Returns the payload when this value is the success case.

Source

pub fn error(&self) -> Option<&OpError>

Returns the error when this value is the failure case.

Source

pub fn into_result(self) -> Result<T, OpError>

Consumes the envelope and returns the success payload or the operation error.

version is not part of the result. A caller that still needs the contract version reads version before calling this method.

§Errors

Returns Err when the envelope is the failure case. The error is the OpError the envelope carried.

§Examples
use sc_command::Envelope;

let envelope = Envelope::success("ready");
assert_eq!(envelope.into_result(), Ok("ready"));

Trait Implementations§

Source§

impl<T: Clone> Clone for Envelope<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Envelope<T>

Source§

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

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

impl<'de, T> Deserialize<'de> for Envelope<T>

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T> From<Result<T, OpError>> for Envelope<T>

Source§

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

Converts to this type from the input type.
Source§

impl<T: PartialEq> PartialEq for Envelope<T>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<T> Serialize for Envelope<T>
where T: Serialize,

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T: PartialEq> StructuralPartialEq for Envelope<T>

Auto Trait Implementations§

§

impl<T> Forget for Envelope<T>

§

impl<T> Freeze for Envelope<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Envelope<T>
where T: RefUnwindSafe,

§

impl<T> Send for Envelope<T>
where T: Send,

§

impl<T> Sync for Envelope<T>
where T: Sync,

§

impl<T> Unpin for Envelope<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Envelope<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Envelope<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where 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> Observable for T
where T: Send + Sync + 'static,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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.