Skip to main content

Client

Struct Client 

Source
pub struct Client<T> { /* private fields */ }
Expand description

A cache in front of a transport.

Implementations§

Source§

impl<T: Transport> Client<T>

Source

pub fn new(transport: T, cache: Cache, mode: Mode) -> Self

A client over transport and cache, in mode.

Source

pub fn mode(&self) -> Mode

The mode the client is in.

Source

pub fn fetch( &self, source: &Source, url: &str, now_s: u64, ) -> Result<Fetched, NetError>

The body at url from source, at time now_s (seconds since the Unix epoch).

A cached copy younger than source.ttl_s is returned as Freshness::Cached without a fetch. Otherwise, online, the transport is called and its body cached; if it fails, a stale copy is returned as Freshness::Stale when there is one. Offline, the transport is never called: any cached copy is returned, Freshness::Stale if it is past its TTL.

A copy dated after now_s is never fresh. Online, a cache entry that cannot be read is treated as missing and overwritten by the fetch.

§Errors

NetError::NotCached offline with no copy; NetError::Transport online when the fetch fails with no copy; cache errors as Cache::get and Cache::put give them.

Source

pub fn fetch_checked( &self, source: &Source, url: &str, now_s: u64, check: impl Fn(&[u8]) -> Result<(), String>, ) -> Result<Fetched, NetError>

As Client::fetch, but only a body that check accepts is cached or returned: a data source passes its parser, so an answer it can’t read (an error page served as 200, a forecast with its hours still empty) is never kept in place of a good copy.

Online, a fetched body the check refuses is not cached; a stale copy is returned in its place, with the reason, when there is one. A cached copy the check refuses counts as missing online, and is the error offline.

§Errors

As Client::fetch, and NetError::Refused when the check refuses the only body there is.

Trait Implementations§

Source§

impl<T: Debug> Debug for Client<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Client<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Client<T>
where T: RefUnwindSafe,

§

impl<T> Send for Client<T>
where T: Send,

§

impl<T> Sync for Client<T>
where T: Sync,

§

impl<T> Unpin for Client<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Client<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Client<T>
where T: UnwindSafe,

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.