#[non_exhaustive]pub struct Answer {Show 14 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 detail: Option<ForeignDetail>,
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; since 0.3.7
(spec-0.4.3) also E_FOREIGN_UNAVAILABLE with its detail (Answer::foreign_unavailable). 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
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.outcome: AnswerOutcomeThe 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).
detail: Option<ForeignDetail>What failed in reaching a foreign mesh: with E_FOREIGN_UNAVAILABLE only, and always
with it (error, 502; spec-0.4.3).
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
impl Answer
Sourcepub fn ok(receipt: Receipt, trust: TrustLabel) -> Answer
pub fn ok(receipt: Receipt, trust: TrustLabel) -> Answer
ok (200): receipt, served with trust.
Sourcepub fn stale(receipt: Receipt, trust: TrustLabel, age_seconds: u64) -> Answer
pub fn stale(receipt: Receipt, trust: TrustLabel, age_seconds: u64) -> Answer
stale (200): the last receipt known, last confirmed age_seconds ago.
Sourcepub fn not_covered() -> Answer
pub fn not_covered() -> Answer
not_covered (404).
Sourcepub fn unlicensed() -> Answer
pub fn unlicensed() -> Answer
unlicensed (403).
Sourcepub fn payment_required(quote: Quote) -> Answer
pub fn payment_required(quote: Quote) -> Answer
payment_required (402) with its quote.
Sourcepub fn rate_limited(retry_after_seconds: u64) -> Answer
pub fn rate_limited(retry_after_seconds: u64) -> Answer
rate_limited (429): retry after this many seconds.
Sourcepub fn bad_request(code: ErrorCode) -> Result<Answer>
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.
Sourcepub fn error(code: ErrorCode) -> Result<Answer>
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).
E_FOREIGN_UNAVAILABLE needs a detail and HTTP 502: build it with
Answer::foreign_unavailable (here it is E_ENVELOPE).
error with E_FOREIGN_UNAVAILABLE and detail (5.5, spec-0.4.3), HTTP 502: the cell
belongs to another mesh, which could not be reached. Answered by a resolver, or by a mesh
fetching across meshes, when no HTTP response came back from the foreign host. Its
status must stay 502 (Answer::with_status to another fails check_answer).
Sourcepub fn with_fn_hash(self, fn_hash: &str) -> Result<Answer>
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.
Sourcepub fn with_fault(self, fault: Fault) -> Answer
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.
Sourcepub fn with_error(self, code: ErrorCode) -> Result<Answer>
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.
Sourcepub fn with_superseded(
self,
superseded_by: &str,
reason: Option<&str>,
) -> Answer
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.
Sourcepub fn with_status(self, status: u16) -> Answer
pub fn with_status(self, status: u16) -> Answer
The HTTP status to send, for an error within 500-599 (other outcomes have one status).