trillium_cookies/
cookies_conn_ext.rs1use cookie::{Cookie, CookieJar};
2use trillium::Conn;
3
4pub trait CookiesConnExt {
9 fn with_cookie<'a>(self, cookie: impl Into<Cookie<'a>>) -> Self;
11 fn cookies(&self) -> &CookieJar;
13 fn cookies_mut(&mut self) -> &mut CookieJar;
15}
16
17impl CookiesConnExt for Conn {
18 fn cookies(&self) -> &CookieJar {
19 self.state()
20 .expect("Cookies handler must be executed before calling CookiesExt::cookies")
21 }
22
23 fn with_cookie<'a>(mut self, cookie: impl Into<Cookie<'a>>) -> Self {
24 self.cookies_mut().add(cookie.into().into_owned());
25 self
26 }
27
28 fn cookies_mut(&mut self) -> &mut CookieJar {
29 self.state_mut()
30 .expect("Cookies handler must be executed before calling CookiesExt::cookies_mut")
31 }
32}