Skip to main content

Answer

Struct Answer 

Source
#[non_exhaustive]
pub struct Answer {
Show 13 fields pub outcome: AnswerOutcome, pub receipt: Option<Receipt>, pub trust: Option<TrustLabel>, pub age_seconds: Option<u64>, pub superseded_by: Option<String>, pub reason: Option<String>, pub quote: Option<Quote>, pub retry_after_seconds: Option<u64>, pub error: Option<ErrorCode>, pub fault: Option<Fault>, pub fn_hash: Option<String>, pub pending: Option<Pending>, pub page: Option<SlicePage>, /* private fields */
}
Expand description

An envelope of spec-0.4.2 (5.5), checked or to be written: every outcome, trust label and member, with a slice page (5.6) for the ok answer of the slice endpoint. As a builder: one constructor per outcome, with_* for the optional members, Answer::to_json for the body and Answer::status for the HTTP status; check the body back with check_answer (or check_slice_answer) to hold it to every rule.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§outcome: AnswerOutcome

The outcome.

§receipt: Option<Receipt>

The receipt (ok, stale; not a slice page’s).

§trust: Option<TrustLabel>

The trust label (ok, stale).

§age_seconds: Option<u64>

Seconds since the mesh last confirmed the receipt (stale).

§superseded_by: Option<String>

Hash of a newer receipt for the same cell.

§reason: Option<String>

Why the receipt was superseded.

§quote: Option<Quote>

The quote (payment_required).

§retry_after_seconds: Option<u64>

Seconds to wait (rate_limited).

§error: Option<ErrorCode>

The code (bad_request, error, and E_NAME_UNBOUND in not_covered).

§fault: Option<Fault>

The formula evaluation fault (not_covered).

§fn_hash: Option<String>

The function the answer is of: a pin’s echo, or the hash the name resolved to.

§pending: Option<Pending>

The pending envelope’s members.

§page: Option<SlicePage>

The slice page (ok at the slice endpoint).

Implementations§

Source§

impl Answer

Source

pub fn ok(receipt: Receipt, trust: TrustLabel) -> Answer

ok (200): receipt, served with trust.

Source

pub fn stale(receipt: Receipt, trust: TrustLabel, age_seconds: u64) -> Answer

stale (200): the last receipt known, last confirmed age_seconds ago.

Source

pub fn not_covered() -> Answer

not_covered (404).

Source

pub fn unlicensed() -> Answer

unlicensed (403).

Source

pub fn payment_required(quote: Quote) -> Answer

payment_required (402) with its quote.

Source

pub fn rate_limited(retry_after_seconds: u64) -> Answer

rate_limited (429): retry after this many seconds.

Source

pub fn bad_request(code: ErrorCode) -> Result<Answer>

bad_request (400) with a code it can carry (5.5: a parse code, E_CANON_HEX, E_SLICE_AT_CELL, or E_JOB_UNKNOWN at a job URL); E_ENVELOPE otherwise.

Source

pub fn error(code: ErrorCode) -> Result<Answer>

error (500; see Answer::with_status) with a code it can carry (any of 10.2 but E_ENVELOPE, E_JOB_UNKNOWN, E_SLICE_AT_CELL and E_NAME_UNBOUND).

Source

pub fn pending(p: Pending) -> Answer

pending (202).

Source

pub fn page(page: SlicePage) -> Answer

The ok answer of the slice endpoint (5.6).

Source

pub fn with_fn_hash(self, fn_hash: &str) -> Result<Answer>

With the fn_hash echo (64 lowercase hex digits; not on pending); E_ENVELOPE otherwise.

Source

pub fn with_fault(self, fault: Fault) -> Answer

A not_covered answer with a formula evaluation fault. Not checked here: a fault with error, or on another outcome, fails check_answer.

Source

pub fn with_error(self, code: ErrorCode) -> Result<Answer>

A not_covered answer with error (only E_NAME_UNBOUND, and not with a fault); E_ENVELOPE otherwise.

Source

pub fn with_superseded( self, superseded_by: &str, reason: Option<&str>, ) -> Answer

An ok or stale answer pointing to a newer receipt, with an optional reason.

Source

pub fn with_status(self, status: u16) -> Answer

The HTTP status to send, for an error within 500-599 (other outcomes have one status).

Source

pub fn status(&self) -> u16

The HTTP status: the outcome’s, or for a checked answer the one received.

Source

pub fn to_value(&self) -> Value

The JSON form of the envelope.

Source

pub fn to_json(&self) -> Vec<u8> ⓘ

The envelope’s body: its canonical JSON text (JCS).

Trait Implementations§

Source§

impl Clone for Answer

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 Debug for Answer

Source§

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

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

impl Eq for Answer

Source§

impl PartialEq for Answer

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 StructuralPartialEq for Answer

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> 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> 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> Same for T

Source§

type Output = T

Should always be Self
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.