Skip to main content

Envelope

Struct Envelope 

Source
pub struct Envelope {
    pub api_version: &'static str,
    pub kind: String,
    pub host: String,
    pub status: Status,
    pub data: Option<Value>,
    pub error: Option<ApiError>,
    pub hints: Option<Value>,
}
Expand description

The machine-readable response wrapper for every command.

Fields§

§api_version: &'static str

Schema version, always API_VERSION.

§kind: String

The payload kind (e.g. ServiceList, Error).

§host: String

Host the response pertains to.

§status: Status

Whether the operation succeeded.

§data: Option<Value>

Success payload, present when status is ok.

§error: Option<ApiError>

Error payload, present when status is error.

§hints: Option<Value>

Optional machine-actionable hints (e.g. a reverse command).

Implementations§

Source§

impl Envelope

Source

pub fn ok(kind: &str, host: &str, data: Value) -> Self

Build a success envelope wrapping data.

Source

pub fn error(kind: &str, host: &str, err: ApiError) -> Self

Build an error envelope carrying err.

Source

pub fn with_hints(self, hints: Value) -> Self

Attach machine-actionable hints (e.g. the reversibility hint, Section 8).

Source

pub fn to_json_string(&self) -> String

Serialize the envelope to a pretty-printed JSON string.

Returns a valid fez/v1 error envelope on serialization failure so that callers always receive syntactically correct JSON.

Trait Implementations§

Source§

impl Serialize for Envelope

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

Auto Trait Implementations§

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

Source§

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