Skip to content

Commit 5099f28

Browse files
committed
feat(builder): add value method
1 parent cf37d0a commit 5099f28

File tree

2 files changed

+171
-87
lines changed

2 files changed

+171
-87
lines changed

src/builder.rs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use std::borrow::{Cow, Borrow, BorrowMut};
1+
use std::borrow::{Borrow, BorrowMut, Cow};
22

3-
use crate::{Cookie, SameSite, Expiration};
3+
use crate::{Cookie, Expiration, SameSite};
44

55
/// Structure that follows the builder pattern for building `Cookie` structs.
66
///
@@ -59,10 +59,28 @@ impl<'c> CookieBuilder<'c> {
5959
/// assert_eq!(c.name_value(), ("foo", "bar"));
6060
/// ```
6161
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>>,
6465
{
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
6684
}
6785

6886
/// Sets the `expires` field in the cookie being built.
@@ -353,7 +371,10 @@ impl<'c> CookieBuilder<'c> {
353371
/// Instead of using this method, pass a `CookieBuilder` directly into
354372
/// methods expecting a `T: Into<Cookie>`. For other cases, use
355373
/// [`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+
)]
357378
pub fn finish(self) -> Cookie<'c> {
358379
self.cookie
359380
}

0 commit comments

Comments
 (0)