use std::borrow::Cow;
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct ResponseCookieId<'c> {
pub(crate) name: Cow<'c, str>,
pub(crate) domain: Option<Cow<'c, str>>,
pub(crate) path: Option<Cow<'c, str>>,
}
impl<'c> ResponseCookieId<'c> {
pub fn new<N: Into<Cow<'c, str>>>(name: N) -> ResponseCookieId<'c> {
ResponseCookieId {
name: name.into(),
domain: None,
path: None,
}
}
pub fn set_domain<P: Into<Cow<'c, str>>>(mut self, domain: P) -> ResponseCookieId<'c> {
self.domain = Some(domain.into());
self
}
pub fn unset_domain(mut self) -> ResponseCookieId<'c> {
self.domain = None;
self
}
pub fn set_path<P: Into<Cow<'c, str>>>(mut self, path: P) -> ResponseCookieId<'c> {
self.path = Some(path.into());
self
}
pub fn unset_path(mut self) -> ResponseCookieId<'c> {
self.path = None;
self
}
#[inline]
pub fn name(&self) -> &str {
self.name.as_ref()
}
#[inline]
pub fn domain(&self) -> Option<&str> {
self.domain.as_ref().map(|d| d.as_ref())
}
#[inline]
pub fn path(&self) -> Option<&str> {
self.path.as_ref().map(|p| p.as_ref())
}
}
impl<'a> From<&'a str> for ResponseCookieId<'a> {
fn from(value: &'a str) -> ResponseCookieId<'a> {
ResponseCookieId {
name: Cow::Borrowed(value),
domain: None,
path: None,
}
}
}