/rust/registry/src/index.crates.io-1949cf8c6b5b557f/headers-0.4.1/src/common/expires.rs
Line | Count | Source |
1 | | use std::time::SystemTime; |
2 | | |
3 | | use crate::util::HttpDate; |
4 | | |
5 | | /// `Expires` header, defined in [RFC7234](https://datatracker.ietf.org/doc/html/rfc7234#section-5.3) |
6 | | /// |
7 | | /// The `Expires` header field gives the date/time after which the |
8 | | /// response is considered stale. |
9 | | /// |
10 | | /// The presence of an Expires field does not imply that the original |
11 | | /// resource will change or cease to exist at, before, or after that |
12 | | /// time. |
13 | | /// |
14 | | /// # ABNF |
15 | | /// |
16 | | /// ```text |
17 | | /// Expires = HTTP-date |
18 | | /// ``` |
19 | | /// |
20 | | /// # Example values |
21 | | /// * `Thu, 01 Dec 1994 16:00:00 GMT` |
22 | | /// |
23 | | /// # Example |
24 | | /// |
25 | | /// ``` |
26 | | /// use headers::Expires; |
27 | | /// use std::time::{SystemTime, Duration}; |
28 | | /// |
29 | | /// let time = SystemTime::now() + Duration::from_secs(60 * 60 * 24); |
30 | | /// let expires = Expires::from(time); |
31 | | /// ``` |
32 | | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] |
33 | | pub struct Expires(HttpDate); |
34 | | |
35 | | derive_header! { |
36 | | Expires(_), |
37 | | name: EXPIRES |
38 | | } |
39 | | |
40 | | impl From<SystemTime> for Expires { |
41 | 0 | fn from(time: SystemTime) -> Expires { |
42 | 0 | Expires(time.into()) |
43 | 0 | } |
44 | | } |
45 | | |
46 | | impl From<Expires> for SystemTime { |
47 | 0 | fn from(date: Expires) -> SystemTime { |
48 | 0 | date.0.into() |
49 | 0 | } |
50 | | } |