|
1 | | -use std::borrow::{Cow, Borrow, BorrowMut}; |
| 1 | +use std::borrow::{Borrow, BorrowMut, Cow}; |
2 | 2 |
|
3 | | -use crate::{Cookie, SameSite, Expiration}; |
| 3 | +use crate::{Cookie, Expiration, SameSite}; |
4 | 4 |
|
5 | 5 | /// Structure that follows the builder pattern for building `Cookie` structs. |
6 | 6 | /// |
@@ -59,10 +59,28 @@ impl<'c> CookieBuilder<'c> { |
59 | 59 | /// assert_eq!(c.name_value(), ("foo", "bar")); |
60 | 60 | /// ``` |
61 | 61 | pub fn new<N, V>(name: N, value: V) -> Self |
62 | | - where N: Into<Cow<'c, str>>, |
63 | | - V: Into<Cow<'c, str>> |
| 62 | + where |
| 63 | + N: Into<Cow<'c, str>>, |
| 64 | + V: Into<Cow<'c, str>>, |
64 | 65 | { |
65 | | - CookieBuilder { cookie: Cookie::new(name, value) } |
| 66 | + CookieBuilder { |
| 67 | + cookie: Cookie::new(name, value), |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + /// Sets the `value` field in the cookie being built. |
| 72 | + /// |
| 73 | + /// # Example |
| 74 | + /// |
| 75 | + /// ```rust |
| 76 | + /// use cookie::Cookie; |
| 77 | + /// |
| 78 | + /// let c = Cookie::build("foo").value("bar"); |
| 79 | + /// assert_eq!(c.inner().name_value(), ("foo", "bar")); |
| 80 | + /// ``` |
| 81 | + pub fn value<V: Into<Cow<'c, str>>>(mut self, value: V) -> Self { |
| 82 | + self.cookie.set_value(value); |
| 83 | + self |
66 | 84 | } |
67 | 85 |
|
68 | 86 | /// Sets the `expires` field in the cookie being built. |
@@ -353,7 +371,10 @@ impl<'c> CookieBuilder<'c> { |
353 | 371 | /// Instead of using this method, pass a `CookieBuilder` directly into |
354 | 372 | /// methods expecting a `T: Into<Cookie>`. For other cases, use |
355 | 373 | /// [`CookieBuilder::build()`]. |
356 | | - #[deprecated(since="0.18.0", note="`CookieBuilder` can be passed in to methods expecting a `Cookie`; for other cases, use `CookieBuilder::build()`")] |
| 374 | + #[deprecated( |
| 375 | + since = "0.18.0", |
| 376 | + note = "`CookieBuilder` can be passed in to methods expecting a `Cookie`; for other cases, use `CookieBuilder::build()`" |
| 377 | + )] |
357 | 378 | pub fn finish(self) -> Cookie<'c> { |
358 | 379 | self.cookie |
359 | 380 | } |
|
0 commit comments