use cookie::{Cookie, CookieJar};
use trillium::Conn;
pub trait CookiesConnExt {
fn with_cookie<'a>(self, cookie: impl Into<Cookie<'a>>) -> Self;
fn cookies(&self) -> &CookieJar;
fn cookies_mut(&mut self) -> &mut CookieJar;
}
impl CookiesConnExt for Conn {
fn cookies(&self) -> &CookieJar {
self.state()
.expect("Cookies handler must be executed before calling CookiesExt::cookies")
}
fn with_cookie<'a>(mut self, cookie: impl Into<Cookie<'a>>) -> Self {
self.cookies_mut().add(cookie.into().into_owned());
self
}
fn cookies_mut(&mut self) -> &mut CookieJar {
self.state_mut()
.expect("Cookies handler must be executed before calling CookiesExt::cookies_mut")
}
}