pub trait Fetch {
// Required method
fn fetch(&self, url: &str) -> Fetched;
}Expand description
How a served identity is fetched. Behind a trait so that every verdict can be tested without a network, and so that the one implementation that does reach the network is a single, reviewable place.
use majordomus_cli::served::{Fetch, Fetched};
struct Canned;
impl Fetch for Canned {
fn fetch(&self, _: &str) -> Fetched { Fetched::Body(b"{}".to_vec()) }
}
assert_eq!(Canned.fetch("https://example.test/build.json"), Fetched::Body(b"{}".to_vec()));Required Methods§
Sourcefn fetch(&self, url: &str) -> Fetched
fn fetch(&self, url: &str) -> Fetched
Fetches url once, bounded. An implementation never retries: a caller that wants a
second look decides that itself, with its own clock.
use majordomus_cli::served::{Curl, Fetch, Fetched};
// nothing listens on the discard port, so the probe answers with a reason
let got = Curl { max_seconds: 2 }.fetch("http://127.0.0.1:9/build.json");
assert!(matches!(got, Fetched::Unreachable(_)));Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".