#[non_exhaustive]pub struct Answer {Show 19 fields
pub outcome: AnswerOutcome,
pub receipt: Option<Receipt>,
pub withdrawn: Option<Withdrawal>,
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>,
pub resolved: Option<Resolved>,
pub shadows: Option<Shadows>,
pub scenario: Option<Scenario>,
pub cycle: Option<Cycle>,
/* 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).
withdrawn: Option<Withdrawal>The withdrawal of a not_covered answer (5.5, spec-0.7.0): the cell’s latest version as of the
asof is a withdrawal. Then receipt is None, and reason is the withdrawal’s withdrawn.
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).
resolved: Option<Resolved>What a short call resolved (ok, stale, not_covered, unlicensed,
payment_required, error; 5.5, spec-0.5.0).
shadows: Option<Shadows>The class this mesh binds to another hash than its reference class (the same outcomes as
resolved; 5.5, 16.9, spec-0.5.0).
scenario: Option<Scenario>The scenario of a whatif request (scenario, 5.9, spec-0.6.0).
cycle: Option<Cycle>The path of an evaluation cycle (error with E_EVAL_UNAVAILABLE, 5.5, spec-0.6.0).
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 withdrawn(withdrawal: Withdrawal, trust: TrustLabel) -> Result<Answer>
pub fn withdrawn(withdrawal: Withdrawal, trust: TrustLabel) -> Result<Answer>
not_covered (404) with a withdrawal (5.5, spec-0.7.0): the cell’s latest version as of
the asof is receipt, a withdrawal, served with trust; its reason is the withdrawal’s
withdrawn text. E_ENVELOPE when receipt is not a withdrawal.
Sourcepub fn label_withdrawn(reason: &str) -> Result<Answer>
pub fn label_withdrawn(reason: &str) -> Result<Answer>
not_covered (404) with reason alone (5.5, 16.7, spec-0.7.0): a label whose lookup cell
is withdrawn, which has no receipt. E_ENVELOPE when reason is empty or too long.
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, E_SHORT_ID_AMBIGUOUS, E_KEY_NORMALISATION or E_KEY_ENCODING
(since spec-0.5.0), 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
the codes 5.5 refuses in an error envelope: E_ENVELOPE, E_DESCRIBE, the request
codes, the define and write codes and the class codes, since spec-0.5.0).
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 scenario(scenario: Scenario) -> Answer
pub fn scenario(scenario: Scenario) -> Answer
scenario (200, 5.9, spec-0.6.0): the answer to a whatif request. It has no receipt
and no trust; check_answer accepts it only for a request with overrides.
Sourcepub fn with_cycle(self, cycle: Cycle) -> Result<Answer>
pub fn with_cycle(self, cycle: Cycle) -> Result<Answer>
With the cycle member (5.5, spec-0.6.0): only on error with E_EVAL_UNAVAILABLE;
E_ENVELOPE otherwise.
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_resolved(self, resolved: Resolved) -> Result<Answer>
pub fn with_resolved(self, resolved: Resolved) -> Result<Answer>
With the resolved member (spec-0.5.0): allowed on ok, stale, not_covered,
unlicensed, payment_required and error; E_ENVELOPE on rate_limited,
bad_request and pending.
Sourcepub fn with_shadows(self, shadows: Shadows) -> Result<Answer>
pub fn with_shadows(self, shadows: Shadows) -> Result<Answer>
With the shadows member (spec-0.5.0), on the same outcomes as
with_resolved; 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).