Struct ResponseCookie
pub struct ResponseCookie<'c> { /* private fields */ }Expand description
A cookie set by a server in an HTTP response using the Set-Cookie header.
§Constructing a ResponseCookie
To construct a cookie with only a name/value, use ResponseCookie::new():
use biscotti::ResponseCookie;
let cookie = ResponseCookie::new("name", "value");
assert_eq!(cookie.to_string(), "name=value");§Building a ResponseCookie
To construct more elaborate cookies, use ResponseCookie’s set_* methods.
use biscotti::ResponseCookie;
let cookie = ResponseCookie::new("name", "value")
.set_domain("www.rust-lang.org")
.set_path("/")
.set_secure(true)
.set_http_only(true);Implementations§
§impl<'c> ResponseCookie<'c>
impl<'c> ResponseCookie<'c>
pub fn new<N, V>(name: N, value: V) -> ResponseCookie<'c>
pub fn new<N, V>(name: N, value: V) -> ResponseCookie<'c>
Creates a new ResponseCookie with the given name and value.
§Example
use biscotti::ResponseCookie;
let cookie = ResponseCookie::new("name", "value");
assert_eq!(cookie.name_value(), ("name", "value"));
// This is equivalent to `from` with a `(name, value)` tuple:
let cookie = ResponseCookie::from(("name", "value"));
assert_eq!(cookie.name_value(), ("name", "value"));pub fn into_owned(self) -> ResponseCookie<'static>
pub fn into_owned(self) -> ResponseCookie<'static>
Converts self into a ResponseCookie with a static lifetime with as few
allocations as possible.
§Example
use biscotti::ResponseCookie;
let c = ResponseCookie::new("a", "b");
let owned_cookie = c.into_owned();
assert_eq!(owned_cookie.name_value(), ("a", "b"));pub fn name(&self) -> &str
pub fn name(&self) -> &str
Returns the name of self.
§Example
use biscotti::ResponseCookie;
let c = ResponseCookie::new("name", "value");
assert_eq!(c.name(), "name");pub fn value(&self) -> &str
pub fn value(&self) -> &str
Returns the value of self.
Does not strip surrounding quotes. See ResponseCookie::value_trimmed() for a
version that does.
§Example
use biscotti::ResponseCookie;
let c = ResponseCookie::new("name", "value");
assert_eq!(c.value(), "value");
let c = ResponseCookie::new("name", "\"value\"");
assert_eq!(c.value(), "\"value\"");pub fn value_trimmed(&self) -> &str
pub fn value_trimmed(&self) -> &str
Returns the value of self with surrounding double-quotes trimmed.
This is not the value of the cookie (that is ResponseCookie::value()).
Instead, this is the value with a surrounding pair of double-quotes, if
any, trimmed away. Quotes are only trimmed when they form a pair and
never otherwise. The trimmed value is never used for other operations,
such as equality checking, on self.
§Example
use biscotti::ResponseCookie;
let c0 = ResponseCookie::new("name", "value");
assert_eq!(c0.value_trimmed(), "value");
let c = ResponseCookie::new("name", "\"value\"");
assert_eq!(c.value_trimmed(), "value");
assert!(c != c0);
let c = ResponseCookie::new("name", "\"value");
assert_eq!(c.value(), "\"value");
assert_eq!(c.value_trimmed(), "\"value");
assert!(c != c0);
let c = ResponseCookie::new("name", "\"value\"\"");
assert_eq!(c.value(), "\"value\"\"");
assert_eq!(c.value_trimmed(), "value\"");
assert!(c != c0);pub fn name_value(&self) -> (&str, &str)
pub fn name_value(&self) -> (&str, &str)
Returns the name and value of self as a tuple of (name, value).
§Example
use biscotti::ResponseCookie;
let c = ResponseCookie::new("name", "value");
assert_eq!(c.name_value(), ("name", "value"));pub fn name_value_trimmed(&self) -> (&str, &str)
pub fn name_value_trimmed(&self) -> (&str, &str)
Returns the name and trimmed value of self
as a tuple of (name, trimmed_value).
§Example
use biscotti::ResponseCookie;
let c = ResponseCookie::new("name", "\"value\"");
assert_eq!(c.name_value_trimmed(), ("name", "value"));pub fn http_only(&self) -> Option<bool>
pub fn http_only(&self) -> Option<bool>
Returns whether this cookie was marked HttpOnly or not. Returns
Some(true) when the cookie was explicitly set (manually or parsed) as
HttpOnly, Some(false) when http_only was manually set to false,
and None otherwise.
§Example
use biscotti::ResponseCookie;
let mut c = ResponseCookie::new("name", "value");
assert_eq!(c.http_only(), None);
// An explicitly set "false" value.
c = c.set_http_only(false);
assert_eq!(c.http_only(), Some(false));
// An explicitly set "true" value.
c = c.set_http_only(true);
assert_eq!(c.http_only(), Some(true));pub fn secure(&self) -> Option<bool>
pub fn secure(&self) -> Option<bool>
Returns whether this cookie was marked Secure or not. Returns
Some(true) when the cookie was explicitly set (manually or parsed) as
Secure, Some(false) when secure was manually set to false, and
None otherwise.
§Example
use biscotti::ResponseCookie;
let mut c = ResponseCookie::new("name", "value");
assert_eq!(c.secure(), None);
// An explicitly set "false" value.
c = c.set_secure(false);
assert_eq!(c.secure(), Some(false));
// An explicitly set "true" value.
c = c.set_secure(true);
assert_eq!(c.secure(), Some(true));pub fn same_site(&self) -> Option<SameSite>
pub fn same_site(&self) -> Option<SameSite>
Returns the SameSite attribute of this cookie if one was specified.
§Example
use biscotti::{ResponseCookie, SameSite};
let mut c = ResponseCookie::new("name", "value");
assert_eq!(c.same_site(), None);
c = c.set_same_site(SameSite::Lax);
assert_eq!(c.same_site(), Some(SameSite::Lax));
c = c.set_same_site(None);
assert_eq!(c.same_site(), None);pub fn partitioned(&self) -> Option<bool>
pub fn partitioned(&self) -> Option<bool>
Returns whether this cookie was marked Partitioned or not. Returns
Some(true) when the cookie was explicitly set (manually or parsed) as
Partitioned, Some(false) when partitioned was manually set to false,
and None otherwise.
Note: This cookie attribute is experimental! Its meaning and definition are not standardized and therefore subject to change.
§Example
use biscotti::ResponseCookie;
let mut c = ResponseCookie::new("name", "value");
assert_eq!(c.partitioned(), None);
// An explicitly set "false" value.
c = c.set_partitioned(false);
assert_eq!(c.partitioned(), Some(false));
// An explicitly set "true" value.
c = c.set_partitioned(true);
assert_eq!(c.partitioned(), Some(true));pub fn max_age(&self) -> Option<SignedDuration>
pub fn max_age(&self) -> Option<SignedDuration>
Returns the specified max-age of the cookie if one was specified.
§Example
use biscotti::{ResponseCookie, time::SignedDuration};
let mut c = ResponseCookie::new("name", "value");
assert_eq!(c.max_age(), None);
c = c.set_max_age(SignedDuration::from_hours(1));
assert_eq!(c.max_age().map(|age| age.as_hours()), Some(1));pub fn path(&self) -> Option<&str>
pub fn path(&self) -> Option<&str>
Returns the Path of the cookie if one was specified.
§Example
use biscotti::ResponseCookie;
let mut c = ResponseCookie::new("name", "value");
assert_eq!(c.path(), None);
c = c.set_path("/");
assert_eq!(c.path(), Some("/"));
c = c.unset_path();
assert_eq!(c.path(), None);pub fn domain(&self) -> Option<&str>
pub fn domain(&self) -> Option<&str>
Returns the Domain of the cookie if one was specified.
This does not consider whether the Domain is valid; validation is left
to higher-level libraries, as needed. However, if the Domain starts
with a leading ., the leading . is stripped.
§Example
use biscotti::ResponseCookie;
let mut c = ResponseCookie::new("name", "value");
assert_eq!(c.domain(), None);
c = c.set_domain("crates.io");
assert_eq!(c.domain(), Some("crates.io"));
c = c.set_domain(".crates.io");
assert_eq!(c.domain(), Some("crates.io"));
// Note that `..crates.io` is not a valid domain.
c = c.set_domain("..crates.io");
assert_eq!(c.domain(), Some(".crates.io"));
c = c.unset_domain();
assert_eq!(c.domain(), None);pub fn expires(&self) -> Option<&Expiration>
pub fn expires(&self) -> Option<&Expiration>
Returns the Expiration of the cookie if one was specified.
§Example
use biscotti::{ResponseCookie, Expiration};
use biscotti::time::{tz::TimeZone, civil::date};
let mut c = ResponseCookie::new("name", "value");
assert_eq!(c.expires(), None);
c = c.set_expires(None);
assert_eq!(c.expires(), Some(&Expiration::Session));
let expire_time = date(2017, 10, 21)
.at(7, 28, 0, 0)
.to_zoned(TimeZone::UTC)
.unwrap();
c = c.set_expires(Some(expire_time));
assert_eq!(c.expires().and_then(|e| e.datetime()).map(|t| t.year()), Some(2017));pub fn expires_datetime(&self) -> Option<&Zoned>
pub fn expires_datetime(&self) -> Option<&Zoned>
Returns the expiration date-time of the cookie if one was specified.
It returns None if the cookie is a session cookie or if the expiration
was not specified.
§Example
use biscotti::{Expiration, ResponseCookie};
use biscotti::time::{civil::date, tz::TimeZone};
let mut c = ResponseCookie::new("name", "value");
assert_eq!(c.expires_datetime(), None);
// Here, `cookie.expires()` returns `Some(Expiration::Session)`.
c = c.set_expires(Expiration::Session);
assert_eq!(c.expires_datetime(), None);
let expire_time = date(2017, 10, 21)
.at(7, 28, 0, 0)
.to_zoned(TimeZone::UTC)
.unwrap();
c = c.set_expires(Some(expire_time));
assert_eq!(c.expires_datetime().map(|t| t.year()), Some(2017));pub fn set_name<N>(self, name: N) -> ResponseCookie<'c>
pub fn set_name<N>(self, name: N) -> ResponseCookie<'c>
Sets the name of self to name.
§Example
use biscotti::ResponseCookie;
let mut c = ResponseCookie::new("name", "value");
assert_eq!(c.name(), "name");
c = c.set_name("foo");
assert_eq!(c.name(), "foo");pub fn set_value<V>(self, value: V) -> ResponseCookie<'c>
pub fn set_value<V>(self, value: V) -> ResponseCookie<'c>
Sets the value of self to value.
§Example
use biscotti::ResponseCookie;
let mut c = ResponseCookie::new("name", "value");
assert_eq!(c.value(), "value");
c = c.set_value("bar");
assert_eq!(c.value(), "bar");pub fn set_http_only<T>(self, value: T) -> ResponseCookie<'c>
pub fn set_http_only<T>(self, value: T) -> ResponseCookie<'c>
Sets the value of http_only in self to value. If value is
None, the field is unset.
§Example
use biscotti::ResponseCookie;
let mut c = ResponseCookie::new("name", "value");
assert_eq!(c.http_only(), None);
c = c.set_http_only(true);
assert_eq!(c.http_only(), Some(true));
c = c.set_http_only(false);
assert_eq!(c.http_only(), Some(false));
c = c.set_http_only(None);
assert_eq!(c.http_only(), None);pub fn set_secure<T>(self, value: T) -> ResponseCookie<'c>
pub fn set_secure<T>(self, value: T) -> ResponseCookie<'c>
Sets the value of secure in self to value. If value is None,
the field is unset.
§Example
use biscotti::ResponseCookie;
let mut c = ResponseCookie::new("name", "value");
assert_eq!(c.secure(), None);
c = c.set_secure(true);
assert_eq!(c.secure(), Some(true));
c = c.set_secure(false);
assert_eq!(c.secure(), Some(false));
c = c.set_secure(None);
assert_eq!(c.secure(), None);pub fn set_same_site<T>(self, value: T) -> ResponseCookie<'c>
pub fn set_same_site<T>(self, value: T) -> ResponseCookie<'c>
Sets the value of same_site in self to value. If value is
None, the field is unset.
§Example
use biscotti::{ResponseCookie, SameSite};
let mut c = ResponseCookie::new("name", "value");
assert_eq!(c.same_site(), None);
c = c.set_same_site(SameSite::Strict);
assert_eq!(c.same_site(), Some(SameSite::Strict));
assert_eq!(c.to_string(), "name=value; SameSite=Strict");
c = c.set_same_site(None);
assert_eq!(c.same_site(), None);
assert_eq!(c.to_string(), "name=value");§Example: SameSite::None
If value is SameSite::None, the “Secure”
flag will be set when the cookie is written out unless secure is
explicitly set to false via ResponseCookie::set_secure() or the equivalent
builder method.
use biscotti::{ResponseCookie, SameSite};
let mut c = ResponseCookie::new("name", "value");
assert_eq!(c.same_site(), None);
c = c.set_same_site(SameSite::None);
assert_eq!(c.same_site(), Some(SameSite::None));
assert_eq!(c.to_string(), "name=value; SameSite=None; Secure");
c = c.set_secure(false);
assert_eq!(c.to_string(), "name=value; SameSite=None");pub fn set_partitioned<T>(self, value: T) -> ResponseCookie<'c>
pub fn set_partitioned<T>(self, value: T) -> ResponseCookie<'c>
Sets the value of partitioned in self to value. If value is
None, the field is unset.
Note: Partitioned cookies require the Secure attribute to be
set. As such, Partitioned cookies are always rendered with the
Secure attribute, irrespective of the Secure attribute’s setting.
Note: This cookie attribute is an HTTP draft! Its meaning and definition are not standardized and therefore subject to change.
§Example
use biscotti::ResponseCookie;
let mut c = ResponseCookie::new("name", "value");
assert_eq!(c.partitioned(), None);
c = c.set_partitioned(true);
assert_eq!(c.partitioned(), Some(true));
assert!(c.to_string().contains("Secure"));
c = c.set_partitioned(false);
assert_eq!(c.partitioned(), Some(false));
assert!(!c.to_string().contains("Secure"));
c = c.set_partitioned(None);
assert_eq!(c.partitioned(), None);
assert!(!c.to_string().contains("Secure"));pub fn set_max_age<D>(self, value: D) -> ResponseCookie<'c>
pub fn set_max_age<D>(self, value: D) -> ResponseCookie<'c>
Sets the value of max_age in self to value. If value is None,
the field is unset.
§Example
use biscotti::{ResponseCookie, time::SignedDuration};
let mut c = ResponseCookie::new("name", "value");
assert_eq!(c.max_age(), None);
let max_age = SignedDuration::from_hours(10);
c = c.set_max_age(max_age);
assert_eq!(c.max_age(), Some(max_age));
c = c.set_max_age(None);
assert!(c.max_age().is_none());pub fn set_path<P>(self, path: P) -> ResponseCookie<'c>
pub fn set_path<P>(self, path: P) -> ResponseCookie<'c>
Sets the path of self to path.
§Example
use biscotti::ResponseCookie;
let mut c = ResponseCookie::new("name", "value");
assert_eq!(c.path(), None);
c = c.set_path("/");
assert_eq!(c.path(), Some("/"));pub fn unset_path(self) -> ResponseCookie<'c>
pub fn unset_path(self) -> ResponseCookie<'c>
Unsets the path of self.
§Example
use biscotti::ResponseCookie;
let mut c = ResponseCookie::new("name", "value");
assert_eq!(c.path(), None);
c = c.set_path("/");
assert_eq!(c.path(), Some("/"));
c = c.unset_path();
assert_eq!(c.path(), None);pub fn set_domain<D>(self, domain: D) -> ResponseCookie<'c>
pub fn set_domain<D>(self, domain: D) -> ResponseCookie<'c>
Sets the domain of self to domain.
§Example
use biscotti::ResponseCookie;
let mut c = ResponseCookie::new("name", "value");
assert_eq!(c.domain(), None);
c = c.set_domain("rust-lang.org");
assert_eq!(c.domain(), Some("rust-lang.org"));pub fn unset_domain(self) -> ResponseCookie<'c>
pub fn unset_domain(self) -> ResponseCookie<'c>
Unsets the domain of self.
§Example
use biscotti::ResponseCookie;
let mut c = ResponseCookie::new("name", "value");
assert_eq!(c.domain(), None);
c = c.set_domain("rust-lang.org");
assert_eq!(c.domain(), Some("rust-lang.org"));
c = c.unset_domain();
assert_eq!(c.domain(), None);pub fn set_expires<T>(self, time: T) -> ResponseCookie<'c>where
T: Into<Expiration>,
pub fn set_expires<T>(self, time: T) -> ResponseCookie<'c>where
T: Into<Expiration>,
Sets the expires field of self to time. If time is None, an
expiration of Session is set.
§Example
use biscotti::{ResponseCookie, Expiration};
use biscotti::time::{Span, Zoned};
let mut c = ResponseCookie::new("name", "value");
assert_eq!(c.expires(), None);
let mut now = Zoned::now();
now += Span::new().weeks(52);
c = c.set_expires(now);
assert!(c.expires().is_some());
c = c.set_expires(None);
assert_eq!(c.expires(), Some(&Expiration::Session));pub fn unset_expires(self) -> ResponseCookie<'c>
pub fn unset_expires(self) -> ResponseCookie<'c>
Unsets the expires of self.
§Example
use biscotti::{ResponseCookie, Expiration};
let mut c = ResponseCookie::new("name", "value");
assert_eq!(c.expires(), None);
c = c.set_expires(None);
assert_eq!(c.expires(), Some(&Expiration::Session));
c = c.unset_expires();
assert_eq!(c.expires(), None);pub fn make_permanent(self) -> ResponseCookie<'c>
pub fn make_permanent(self) -> ResponseCookie<'c>
Makes self a “permanent” cookie by extending its expiration and max
age 20 years into the future.
§Example
use biscotti::{ResponseCookie, time::SignedDuration};
let mut c = ResponseCookie::new("foo", "bar");
assert!(c.expires().is_none());
assert!(c.max_age().is_none());
c = c.make_permanent();
assert!(c.expires().is_some());
assert_eq!(c.max_age(), Some(SignedDuration::from_hours(24 * 365 * 20)));pub fn into_removal(self) -> RemovalCookie<'c>
pub fn into_removal(self) -> RemovalCookie<'c>
Make self a “removal” cookie by clearing its value and
setting an expiration date far in the past.
§Example
use biscotti::{ResponseCookie, time::Zoned};
let c = ResponseCookie::new("foo", "bar");
let removal = c.into_removal();
// You can convert a `RemovalCookie` back into a "raw" `ResponseCookie`
// to inspect its properties.
let raw: ResponseCookie = removal.into();
assert_eq!(raw.value(), "");
let expiration = raw.expires_datetime().unwrap();
assert!(expiration < Zoned::now());pub fn id(&self) -> ResponseCookieId<'c>
pub fn id(&self) -> ResponseCookieId<'c>
Returns a ResponseCookieId that can be used to identify self in a
collection of response cookies.
It takes into account the name, domain, and path of self.
Trait Implementations§
§impl<'a> AsMut<ResponseCookie<'a>> for ResponseCookie<'a>
impl<'a> AsMut<ResponseCookie<'a>> for ResponseCookie<'a>
§fn as_mut(&mut self) -> &mut ResponseCookie<'a>
fn as_mut(&mut self) -> &mut ResponseCookie<'a>
§impl<'a> AsRef<ResponseCookie<'a>> for ResponseCookie<'a>
impl<'a> AsRef<ResponseCookie<'a>> for ResponseCookie<'a>
§fn as_ref(&self) -> &ResponseCookie<'a>
fn as_ref(&self) -> &ResponseCookie<'a>
§impl<'c> Clone for ResponseCookie<'c>
impl<'c> Clone for ResponseCookie<'c>
§fn clone(&self) -> ResponseCookie<'c>
fn clone(&self) -> ResponseCookie<'c>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl<'c> Debug for ResponseCookie<'c>
impl<'c> Debug for ResponseCookie<'c>
§impl Display for ResponseCookie<'_>
impl Display for ResponseCookie<'_>
§impl<'a, N, V> From<(N, V)> for ResponseCookie<'a>
impl<'a, N, V> From<(N, V)> for ResponseCookie<'a>
§fn from(_: (N, V)) -> ResponseCookie<'a>
fn from(_: (N, V)) -> ResponseCookie<'a>
§impl<'c> From<RemovalCookie<'c>> for ResponseCookie<'c>
impl<'c> From<RemovalCookie<'c>> for ResponseCookie<'c>
§fn from(value: RemovalCookie<'c>) -> ResponseCookie<'c>
fn from(value: RemovalCookie<'c>) -> ResponseCookie<'c>
§impl<'b> PartialEq<ResponseCookie<'b>> for ResponseCookie<'_>
impl<'b> PartialEq<ResponseCookie<'b>> for ResponseCookie<'_>
Auto Trait Implementations§
impl<'c> Freeze for ResponseCookie<'c>
impl<'c> RefUnwindSafe for ResponseCookie<'c>
impl<'c> Send for ResponseCookie<'c>
impl<'c> Sync for ResponseCookie<'c>
impl<'c> Unpin for ResponseCookie<'c>
impl<'c> UnwindSafe for ResponseCookie<'c>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute] value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi [Quirk] value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);