Skip to content

Commit cf37d0a

Browse files
jedenastkaSergioBenitez
authored andcommitted
Add 'CookieBuilder::removal()'.
Add a `removal()` method to `CookieBuilder`, a counterpart to `Cookie::make_removal()`, analogous to `CookieBuilder::permanent()`, counterpart to `Cookie::make_permanent()`.
1 parent 273e397 commit cf37d0a

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/builder.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ impl<'c> CookieBuilder<'c> {
212212
}
213213

214214
/// Makes the cookie being built 'permanent' by extending its expiration and
215-
/// max age 20 years into the future.
215+
/// max age 20 years into the future. See also [`Cookie::make_permanent()`].
216216
///
217217
/// # Example
218218
///
@@ -233,6 +233,32 @@ impl<'c> CookieBuilder<'c> {
233233
self
234234
}
235235

236+
/// Makes the cookie being built 'removal' by clearing its value, setting a
237+
/// max-age of `0`, and setting an expiration date far in the past. See also
238+
/// [`Cookie::make_removal()`].
239+
///
240+
/// # Example
241+
///
242+
/// ```rust
243+
/// # extern crate cookie;
244+
/// use cookie::Cookie;
245+
/// use cookie::time::Duration;
246+
///
247+
/// # fn main() {
248+
/// let mut builder = Cookie::build("foo").removal();
249+
/// assert_eq!(builder.inner().max_age(), Some(Duration::ZERO));
250+
///
251+
/// let mut builder = Cookie::build(("name", "value")).removal();
252+
/// assert_eq!(builder.inner().value(), "");
253+
/// assert_eq!(builder.inner().max_age(), Some(Duration::ZERO));
254+
/// # }
255+
/// ```
256+
#[inline]
257+
pub fn removal(mut self) -> Self {
258+
self.cookie.make_removal();
259+
self
260+
}
261+
236262
/// Returns a borrow to the cookie currently being built.
237263
///
238264
/// # Example

0 commit comments

Comments
 (0)