cookies/
lib.rs

1#![cfg_attr(test, deny(warnings))]
2#![deny(missing_docs)]
3#![deny(missing_debug_implementations)]
4
5//! # cookies
6//!
7//! HTTP cookie parsing and building.
8//!
9//! # The `Cookie` trait
10//!
11//! This crate tries something a little different. Instead of representing
12//! a cookie with a single `struct`, the *concept* of a cookie is instead
13//! exposed as a `trait`.
14
15use std::fmt;
16use std::time::Duration;
17
18mod build;
19mod error;
20mod parse;
21mod util;
22
23pub use self::build::Builder;
24pub use self::error::Error;
25pub use self::parse::parse;
26pub use self::util::SameSite;
27
28use self::sealed::Sealed;
29
30/// Cookies in this crate implement this trait.
31pub trait Cookie: fmt::Debug + fmt::Display + Sealed {
32    /// Get the name of this cookie.
33    fn name(&self) -> &str;
34
35    /// Get the value of this cookie.
36    fn value(&self) -> &str;
37
38    /// Get the `Domain`, if set.
39    fn domain(&self) -> Option<&str>;
40
41    /// Get the `Path`, if set.
42    fn path(&self) -> Option<&str>;
43
44    /// Get the `Max-Age`, if set.
45    fn max_age(&self) -> Option<Duration>;
46
47    /// Get if the `HttpOnly` attribute was on this cookie.
48    fn http_only(&self) -> bool;
49
50    /// Get if the `Secure` attribute was on this cookie.
51    fn secure(&self) -> bool;
52
53    /// Get the `SameSite`, if set.
54    fn same_site(&self) -> Option<SameSite>;
55}
56
57mod sealed {
58    pub trait Sealed {}
59}