From fa37205d55c77bcd8eb82d43da9f2c4dcbb0f006 Mon Sep 17 00:00:00 2001 From: Grzesiek11 Date: Thu, 18 Jan 2024 15:06:22 +0100 Subject: [PATCH] Add 'CookieBuilder::removal()'. Add a `removal()` method to `CookieBuilder`, a counterpart to `Cookie::make_removal()`, analogous to `CookieBuilder::permanent()`, counterpart to `Cookie::make_permanent()`. --- src/builder.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/builder.rs b/src/builder.rs index 6c3a6263..8d7e9d59 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -212,7 +212,7 @@ impl<'c> CookieBuilder<'c> { } /// Makes the cookie being built 'permanent' by extending its expiration and - /// max age 20 years into the future. + /// max age 20 years into the future. See also [`Cookie::make_permanent()`]. /// /// # Example /// @@ -233,6 +233,32 @@ impl<'c> CookieBuilder<'c> { self } + /// Makes the cookie being built 'removal' by clearing its value, setting a + /// max-age of `0`, and setting an expiration date far in the past. See also + /// [`Cookie::make_removal()`]. + /// + /// # Example + /// + /// ```rust + /// # extern crate cookie; + /// use cookie::Cookie; + /// use cookie::time::Duration; + /// + /// # fn main() { + /// let mut builder = Cookie::build("foo").removal(); + /// assert_eq!(builder.inner().max_age(), Some(Duration::ZERO)); + /// + /// let mut builder = Cookie::build(("name", "value")).removal(); + /// assert_eq!(builder.inner().value(), ""); + /// assert_eq!(builder.inner().max_age(), Some(Duration::ZERO)); + /// # } + /// ``` + #[inline] + pub fn removal(mut self) -> Self { + self.cookie.make_removal(); + self + } + /// Returns a borrow to the cookie currently being built. /// /// # Example