pub struct Expires { /* private fields */ }Expand description
HTTP Expires header
Specifications
Examples
use http_types::Response;
use http_types::cache::Expires;
use std::time::{SystemTime, Duration};
let time = SystemTime::now() + Duration::from_secs(5 * 60);
let expires = Expires::new_at(time);
let mut res = Response::new(200);
expires.apply(&mut res);
let expires = Expires::from_headers(res)?.unwrap();
// HTTP dates only have second-precision.
let elapsed = time.duration_since(expires.expiration())?;
assert_eq!(elapsed.as_secs(), 0);Implementations
sourceimpl Expires
impl Expires
sourcepub fn new_at(instant: SystemTime) -> Expires
pub fn new_at(instant: SystemTime) -> Expires
Create a new instance of Expires from secs.
sourcepub fn expiration(&self) -> SystemTime
pub fn expiration(&self) -> SystemTime
Get the expiration time.
sourcepub fn from_headers(
headers: impl AsRef<Headers>
) -> Result<Option<Expires>, Error>
pub fn from_headers(
headers: impl AsRef<Headers>
) -> Result<Option<Expires>, Error>
Create an instance of Expires from a Headers instance.
sourcepub fn apply(&self, headers: impl AsMut<Headers>)
pub fn apply(&self, headers: impl AsMut<Headers>)
Insert a HeaderName + HeaderValue pair into a Headers instance.
sourcepub fn name(&self) -> HeaderName
pub fn name(&self) -> HeaderName
Get the HeaderName.
sourcepub fn value(&self) -> HeaderValue
pub fn value(&self) -> HeaderValue
Get the HeaderValue.
Trait Implementations
sourceimpl Ord for Expires
impl Ord for Expires
sourceimpl PartialOrd<Expires> for Expires
impl PartialOrd<Expires> for Expires
sourcepub fn partial_cmp(&self, other: &Expires) -> Option<Ordering>
pub fn partial_cmp(&self, other: &Expires) -> Option<Ordering>
This method returns an ordering between self and other values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
sourceimpl ToHeaderValues for Expires
impl ToHeaderValues for Expires
type Iter = IntoIter<HeaderValue>
type Iter = IntoIter<HeaderValue>
Returned iterator over header values which this type may correspond to.
sourcepub fn to_header_values(
&self
) -> Result<<Expires as ToHeaderValues>::Iter, Error>
pub fn to_header_values(
&self
) -> Result<<Expires as ToHeaderValues>::Iter, Error>
Converts this object to an iterator of resolved HeaderValues.
impl Eq for Expires
impl StructuralEq for Expires
impl StructuralPartialEq for Expires
Auto Trait Implementations
impl RefUnwindSafe for Expires
impl Send for Expires
impl Sync for Expires
impl Unpin for Expires
impl UnwindSafe for Expires
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more