Struct elephantry::Time

source ·
#[repr(C)]
pub struct Time { /* private fields */ }
Available on crate feature time only.
Expand description

Rust type for time. The clock time within a given date. Nanosecond precision.

All minutes are assumed to have exactly 60 seconds; no attempt is made to handle leap seconds (either positive or negative).

When comparing two Times, they are assumed to be in the same calendar date.

Implementations§

source§

impl Time

source

pub const MIDNIGHT: Time = Self::MIN

Create a Time that is exactly midnight.

assert_eq!(Time::MIDNIGHT, time!(0:00));
source

pub const fn from_hms( hour: u8, minute: u8, second: u8 ) -> Result<Time, ComponentRange>

Attempt to create a Time from the hour, minute, and second.

assert!(Time::from_hms(1, 2, 3).is_ok());
assert!(Time::from_hms(24, 0, 0).is_err()); // 24 isn't a valid hour.
assert!(Time::from_hms(0, 60, 0).is_err()); // 60 isn't a valid minute.
assert!(Time::from_hms(0, 0, 60).is_err()); // 60 isn't a valid second.
source

pub const fn from_hms_milli( hour: u8, minute: u8, second: u8, millisecond: u16 ) -> Result<Time, ComponentRange>

Attempt to create a Time from the hour, minute, second, and millisecond.

assert!(Time::from_hms_milli(1, 2, 3, 4).is_ok());
assert!(Time::from_hms_milli(24, 0, 0, 0).is_err()); // 24 isn't a valid hour.
assert!(Time::from_hms_milli(0, 60, 0, 0).is_err()); // 60 isn't a valid minute.
assert!(Time::from_hms_milli(0, 0, 60, 0).is_err()); // 60 isn't a valid second.
assert!(Time::from_hms_milli(0, 0, 0, 1_000).is_err()); // 1_000 isn't a valid millisecond.
source

pub const fn from_hms_micro( hour: u8, minute: u8, second: u8, microsecond: u32 ) -> Result<Time, ComponentRange>

Attempt to create a Time from the hour, minute, second, and microsecond.

assert!(Time::from_hms_micro(1, 2, 3, 4).is_ok());
assert!(Time::from_hms_micro(24, 0, 0, 0).is_err()); // 24 isn't a valid hour.
assert!(Time::from_hms_micro(0, 60, 0, 0).is_err()); // 60 isn't a valid minute.
assert!(Time::from_hms_micro(0, 0, 60, 0).is_err()); // 60 isn't a valid second.
assert!(Time::from_hms_micro(0, 0, 0, 1_000_000).is_err()); // 1_000_000 isn't a valid microsecond.
source

pub const fn from_hms_nano( hour: u8, minute: u8, second: u8, nanosecond: u32 ) -> Result<Time, ComponentRange>

Attempt to create a Time from the hour, minute, second, and nanosecond.

assert!(Time::from_hms_nano(1, 2, 3, 4).is_ok());
assert!(Time::from_hms_nano(24, 0, 0, 0).is_err()); // 24 isn't a valid hour.
assert!(Time::from_hms_nano(0, 60, 0, 0).is_err()); // 60 isn't a valid minute.
assert!(Time::from_hms_nano(0, 0, 60, 0).is_err()); // 60 isn't a valid second.
assert!(Time::from_hms_nano(0, 0, 0, 1_000_000_000).is_err()); // 1_000_000_000 isn't a valid nanosecond.
source

pub const fn as_hms(self) -> (u8, u8, u8)

Get the clock hour, minute, and second.

assert_eq!(time!(0:00:00).as_hms(), (0, 0, 0));
assert_eq!(time!(23:59:59).as_hms(), (23, 59, 59));
source

pub const fn as_hms_milli(self) -> (u8, u8, u8, u16)

Get the clock hour, minute, second, and millisecond.

assert_eq!(time!(0:00:00).as_hms_milli(), (0, 0, 0, 0));
assert_eq!(time!(23:59:59.999).as_hms_milli(), (23, 59, 59, 999));
source

pub const fn as_hms_micro(self) -> (u8, u8, u8, u32)

Get the clock hour, minute, second, and microsecond.

assert_eq!(time!(0:00:00).as_hms_micro(), (0, 0, 0, 0));
assert_eq!(
    time!(23:59:59.999_999).as_hms_micro(),
    (23, 59, 59, 999_999)
);
source

pub const fn as_hms_nano(self) -> (u8, u8, u8, u32)

Get the clock hour, minute, second, and nanosecond.

assert_eq!(time!(0:00:00).as_hms_nano(), (0, 0, 0, 0));
assert_eq!(
    time!(23:59:59.999_999_999).as_hms_nano(),
    (23, 59, 59, 999_999_999)
);
source

pub const fn hour(self) -> u8

Get the clock hour.

The returned value will always be in the range 0..24.

assert_eq!(time!(0:00:00).hour(), 0);
assert_eq!(time!(23:59:59).hour(), 23);
source

pub const fn minute(self) -> u8

Get the minute within the hour.

The returned value will always be in the range 0..60.

assert_eq!(time!(0:00:00).minute(), 0);
assert_eq!(time!(23:59:59).minute(), 59);
source

pub const fn second(self) -> u8

Get the second within the minute.

The returned value will always be in the range 0..60.

assert_eq!(time!(0:00:00).second(), 0);
assert_eq!(time!(23:59:59).second(), 59);
source

pub const fn millisecond(self) -> u16

Get the milliseconds within the second.

The returned value will always be in the range 0..1_000.

assert_eq!(time!(0:00).millisecond(), 0);
assert_eq!(time!(23:59:59.999).millisecond(), 999);
source

pub const fn microsecond(self) -> u32

Get the microseconds within the second.

The returned value will always be in the range 0..1_000_000.

assert_eq!(time!(0:00).microsecond(), 0);
assert_eq!(time!(23:59:59.999_999).microsecond(), 999_999);
source

pub const fn nanosecond(self) -> u32

Get the nanoseconds within the second.

The returned value will always be in the range 0..1_000_000_000.

assert_eq!(time!(0:00).nanosecond(), 0);
assert_eq!(time!(23:59:59.999_999_999).nanosecond(), 999_999_999);
source

pub const fn replace_hour(self, hour: u8) -> Result<Time, ComponentRange>

Replace the clock hour.

assert_eq!(
    time!(01:02:03.004_005_006).replace_hour(7),
    Ok(time!(07:02:03.004_005_006))
);
assert!(time!(01:02:03.004_005_006).replace_hour(24).is_err()); // 24 isn't a valid hour
source

pub const fn replace_minute(self, minute: u8) -> Result<Time, ComponentRange>

Replace the minutes within the hour.

assert_eq!(
    time!(01:02:03.004_005_006).replace_minute(7),
    Ok(time!(01:07:03.004_005_006))
);
assert!(time!(01:02:03.004_005_006).replace_minute(60).is_err()); // 60 isn't a valid minute
source

pub const fn replace_second(self, second: u8) -> Result<Time, ComponentRange>

Replace the seconds within the minute.

assert_eq!(
    time!(01:02:03.004_005_006).replace_second(7),
    Ok(time!(01:02:07.004_005_006))
);
assert!(time!(01:02:03.004_005_006).replace_second(60).is_err()); // 60 isn't a valid second
source

pub const fn replace_millisecond( self, millisecond: u16 ) -> Result<Time, ComponentRange>

Replace the milliseconds within the second.

assert_eq!(
    time!(01:02:03.004_005_006).replace_millisecond(7),
    Ok(time!(01:02:03.007))
);
assert!(time!(01:02:03.004_005_006).replace_millisecond(1_000).is_err()); // 1_000 isn't a valid millisecond
source

pub const fn replace_microsecond( self, microsecond: u32 ) -> Result<Time, ComponentRange>

Replace the microseconds within the second.

assert_eq!(
    time!(01:02:03.004_005_006).replace_microsecond(7_008),
    Ok(time!(01:02:03.007_008))
);
assert!(time!(01:02:03.004_005_006).replace_microsecond(1_000_000).is_err()); // 1_000_000 isn't a valid microsecond
source

pub const fn replace_nanosecond( self, nanosecond: u32 ) -> Result<Time, ComponentRange>

Replace the nanoseconds within the second.

assert_eq!(
    time!(01:02:03.004_005_006).replace_nanosecond(7_008_009),
    Ok(time!(01:02:03.007_008_009))
);
assert!(time!(01:02:03.004_005_006).replace_nanosecond(1_000_000_000).is_err()); // 1_000_000_000 isn't a valid nanosecond
source§

impl Time

source

pub fn format_into( self, output: &mut impl Write, format: &(impl Formattable + ?Sized) ) -> Result<usize, Format>

Format the Time using the provided format description.

source

pub fn format( self, format: &(impl Formattable + ?Sized) ) -> Result<String, Format>

Format the Time using the provided format description.

let format = format_description::parse("[hour]:[minute]:[second]")?;
assert_eq!(time!(12:00).format(&format)?, "12:00:00");
source§

impl Time

source

pub fn parse( input: &str, description: &(impl Parsable + ?Sized) ) -> Result<Time, Parse>

Parse a Time from the input using the provided format description.

let format = format_description!("[hour]:[minute]:[second]");
assert_eq!(Time::parse("12:00:00", &format)?, time!(12:00));

Trait Implementations§

source§

impl Add<Duration> for Time

source§

fn add(self, duration: Duration) -> <Time as Add<Duration>>::Output

Add the sub-day time of the std::time::Duration to the Time. Wraps on overflow.

assert_eq!(time!(12:00) + 2.std_hours(), time!(14:00));
assert_eq!(time!(23:59:59) + 2.std_seconds(), time!(0:00:01));
§

type Output = Time

The resulting type after applying the + operator.
source§

impl Add<Duration> for Time

source§

fn add(self, duration: Duration) -> <Time as Add<Duration>>::Output

Add the sub-day time of the Duration to the Time. Wraps on overflow.

assert_eq!(time!(12:00) + 2.hours(), time!(14:00));
assert_eq!(time!(0:00:01) + (-2).seconds(), time!(23:59:59));
§

type Output = Time

The resulting type after applying the + operator.
source§

impl AddAssign<Duration> for Time

source§

fn add_assign(&mut self, rhs: Duration)

Performs the += operation. Read more
source§

impl AddAssign<Duration> for Time

source§

fn add_assign(&mut self, rhs: Duration)

Performs the += operation. Read more
source§

impl Clone for Time

source§

fn clone(&self) -> Time

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Time

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<'a> Deserialize<'a> for Time

source§

fn deserialize<D>( deserializer: D ) -> Result<Time, <D as Deserializer<'a>>::Error>
where D: Deserializer<'a>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Time

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<'v> FromFormField<'v> for Time

source§

fn from_value(field: ValueField<'v>) -> Result<Time, Errors<'v>>

Parse a value of T from a form value field. Read more
source§

fn from_data<'life0, 'async_trait>( field: DataField<'v, 'life0> ) -> Pin<Box<dyn Future<Output = Result<Self, Errors<'v>>> + Send + 'async_trait>>
where 'v: 'async_trait, 'life0: 'async_trait, Self: 'async_trait,

Parse a value of T from a form data field. Read more
source§

fn default() -> Option<Self>

Returns a default value, if any exists, to be used during lenient parsing when the form field is missing. Read more
source§

impl FromSql for Time

source§

fn from_text(ty: &Type, raw: Option<&str>) -> Result<Self>

Create a new struct from the text representation. Read more
source§

fn from_binary(ty: &Type, raw: Option<&[u8]>) -> Result<Self>

Create a new struct from the binary representation. Read more
source§

fn from_sql(ty: &Type, format: Format, raw: Option<&[u8]>) -> Result<Self>

Create a new struct from SQL value.
source§

fn error<T: Debug>(pg_type: &Type, raw: T) -> Error

source§

impl<'x, P> FromUriParam<P, &'x Time> for Time
where P: Part,

§

type Target = &'x Time

The resulting type of this conversion.
source§

fn from_uri_param(param: &'x Time) -> &'x Time

Converts a value of type T into a value of type Self::Target. The resulting value of type Self::Target will be rendered into a URI using its UriDisplay implementation.
source§

impl<'x, P> FromUriParam<P, &'x mut Time> for Time
where P: Part,

§

type Target = &'x mut Time

The resulting type of this conversion.
source§

fn from_uri_param(param: &'x mut Time) -> &'x mut Time

Converts a value of type T into a value of type Self::Target. The resulting value of type Self::Target will be rendered into a URI using its UriDisplay implementation.
source§

impl<P> FromUriParam<P, Time> for Time
where P: Part,

§

type Target = Time

The resulting type of this conversion.
source§

fn from_uri_param(param: Time) -> Time

Converts a value of type T into a value of type Self::Target. The resulting value of type Self::Target will be rendered into a URI using its UriDisplay implementation.
source§

impl Hash for Time

source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for Time

source§

fn cmp(&self, other: &Time) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Time

source§

fn eq(&self, other: &Time) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Time

source§

fn partial_cmp(&self, other: &Time) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for Time

source§

fn serialize<S>( &self, serializer: S ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl SmartDisplay for Time

§

type Metadata = TimeMetadata

User-provided metadata type.
source§

fn metadata(&self, _: FormatterOptions) -> Metadata<'_, Time>

Compute any information needed to format the value. This must, at a minimum, determine the width of the value before any padding is added by the formatter. Read more
source§

fn fmt_with_metadata( &self, f: &mut Formatter<'_>, metadata: Metadata<'_, Time> ) -> Result<(), Error>

Format the value using the given formatter and metadata. The formatted output should have the width indicated by the metadata. This is before any padding is added by the formatter. Read more
source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Format the value using the given formatter. This is the same as Display::fmt. Read more
source§

impl Sub<Duration> for Time

source§

fn sub(self, duration: Duration) -> <Time as Sub<Duration>>::Output

Subtract the sub-day time of the Duration from the Time. Wraps on overflow.

assert_eq!(time!(14:00) - 2.hours(), time!(12:00));
assert_eq!(time!(23:59:59) - (-2).seconds(), time!(0:00:01));
§

type Output = Time

The resulting type after applying the - operator.
source§

impl Sub<Duration> for Time

source§

fn sub(self, duration: Duration) -> <Time as Sub<Duration>>::Output

Subtract the sub-day time of the std::time::Duration from the Time. Wraps on overflow.

assert_eq!(time!(14:00) - 2.std_hours(), time!(12:00));
assert_eq!(time!(0:00:01) - 2.std_seconds(), time!(23:59:59));
§

type Output = Time

The resulting type after applying the - operator.
source§

impl Sub for Time

source§

fn sub(self, rhs: Time) -> <Time as Sub>::Output

Subtract two Times, returning the Duration between. This assumes both Times are in the same calendar day.

assert_eq!(time!(0:00) - time!(0:00), 0.seconds());
assert_eq!(time!(1:00) - time!(0:00), 1.hours());
assert_eq!(time!(0:00) - time!(1:00), (-1).hours());
assert_eq!(time!(0:00) - time!(23:00), (-23).hours());
§

type Output = Duration

The resulting type after applying the - operator.
source§

impl SubAssign<Duration> for Time

source§

fn sub_assign(&mut self, rhs: Duration)

Performs the -= operation. Read more
source§

impl SubAssign<Duration> for Time

source§

fn sub_assign(&mut self, rhs: Duration)

Performs the -= operation. Read more
source§

impl ToSql for Time

source§

fn ty(&self) -> Type

The corresponding SQL type
source§

fn to_text(&self) -> Result<Option<String>>

Convert the value to text format Read more
source§

fn to_binary(&self) -> Result<Option<Vec<u8>>>

Convert the value to binary format Read more
source§

fn error(&self, message: &str) -> Error

source§

impl TryFrom<Parsed> for Time

§

type Error = TryFromParsed

The type returned in the event of a conversion error.
source§

fn try_from(parsed: Parsed) -> Result<Time, <Time as TryFrom<Parsed>>::Error>

Performs the conversion.
source§

impl<P> UriDisplay<P> for Time
where P: Part,

This implementation is identical to a percent-encoded version of the Display implementation.

source§

fn fmt(&self, f: &mut Formatter<'_, P>) -> Result<(), Error>

Formats self in a URI-safe manner using the given formatter.
source§

impl Copy for Time

source§

impl Eq for Time

source§

impl Simple for Time

Auto Trait Implementations§

§

impl Freeze for Time

§

impl RefUnwindSafe for Time

§

impl Send for Time

§

impl Sync for Time

§

impl Unpin for Time

§

impl UnwindSafe for Time

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
source§

impl<T> Entity for T
where T: Simple,

source§

fn from(tuple: &Tuple<'_>) -> T

Create a new struct from SQL result.
source§

fn get(&self, _: &str) -> Option<&dyn ToSql>

Get the value of the field named field.
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<'v, T> FromForm<'v> for T
where T: FromFormField<'v>,

§

type Context = FromFieldContext<'v, T>

The form guard’s parsing context.
source§

fn init(opts: Options) -> <T as FromForm<'v>>::Context

Initializes and returns the parsing context for Self.
source§

fn push_value(ctxt: &mut <T as FromForm<'v>>::Context, field: ValueField<'v>)

Processes the value field field.
source§

fn push_data<'life0, 'life1, 'async_trait>( ctxt: &'life0 mut FromFieldContext<'v, T>, field: DataField<'v, 'life1> ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'v: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, T: 'async_trait,

Processes the data field field.
source§

fn finalize(ctxt: <T as FromForm<'v>>::Context) -> Result<T, Errors<'v>>

Finalizes parsing. Returns the parsed value when successful or collection of Errors otherwise.
source§

fn push_error(_ctxt: &mut Self::Context, _error: Error<'r>)

Processes the external form or field error _error. Read more
source§

fn default(opts: Options) -> Option<Self>

Returns a default value, if any, to use when a value is desired and parsing fails. Read more
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoCollection<T> for T

source§

fn into_collection<A>(self) -> SmallVec<A>
where A: Array<Item = T>,

Converts self into a collection.
source§

fn mapped<U, F, A>(self, f: F) -> SmallVec<A>
where F: FnMut(T) -> U, A: Array<Item = U>,

source§

impl<T> Paint for T
where T: ?Sized,

source§

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();
source§

fn primary(&self) -> Painted<&T>

Returns self with the fg() set to Color::Primary.

§Example
println!("{}", value.primary());
source§

fn fixed(&self, color: u8) -> Painted<&T>

Returns self with the fg() set to Color::Fixed.

§Example
println!("{}", value.fixed(color));
source§

fn rgb(&self, r: u8, g: u8, b: u8) -> Painted<&T>

Returns self with the fg() set to Color::Rgb.

§Example
println!("{}", value.rgb(r, g, b));
source§

fn black(&self) -> Painted<&T>

Returns self with the fg() set to Color::Black.

§Example
println!("{}", value.black());
source§

fn red(&self) -> Painted<&T>

Returns self with the fg() set to Color::Red.

§Example
println!("{}", value.red());
source§

fn green(&self) -> Painted<&T>

Returns self with the fg() set to Color::Green.

§Example
println!("{}", value.green());
source§

fn yellow(&self) -> Painted<&T>

Returns self with the fg() set to Color::Yellow.

§Example
println!("{}", value.yellow());
source§

fn blue(&self) -> Painted<&T>

Returns self with the fg() set to Color::Blue.

§Example
println!("{}", value.blue());
source§

fn magenta(&self) -> Painted<&T>

Returns self with the fg() set to Color::Magenta.

§Example
println!("{}", value.magenta());
source§

fn cyan(&self) -> Painted<&T>

Returns self with the fg() set to Color::Cyan.

§Example
println!("{}", value.cyan());
source§

fn white(&self) -> Painted<&T>

Returns self with the fg() set to Color::White.

§Example
println!("{}", value.white());
source§

fn bright_black(&self) -> Painted<&T>

Returns self with the fg() set to Color::BrightBlack.

§Example
println!("{}", value.bright_black());
source§

fn bright_red(&self) -> Painted<&T>

Returns self with the fg() set to Color::BrightRed.

§Example
println!("{}", value.bright_red());
source§

fn bright_green(&self) -> Painted<&T>

Returns self with the fg() set to Color::BrightGreen.

§Example
println!("{}", value.bright_green());
source§

fn bright_yellow(&self) -> Painted<&T>

Returns self with the fg() set to Color::BrightYellow.

§Example
println!("{}", value.bright_yellow());
source§

fn bright_blue(&self) -> Painted<&T>

Returns self with the fg() set to Color::BrightBlue.

§Example
println!("{}", value.bright_blue());
source§

fn bright_magenta(&self) -> Painted<&T>

Returns self with the fg() set to Color::BrightMagenta.

§Example
println!("{}", value.bright_magenta());
source§

fn bright_cyan(&self) -> Painted<&T>

Returns self with the fg() set to Color::BrightCyan.

§Example
println!("{}", value.bright_cyan());
source§

fn bright_white(&self) -> Painted<&T>

Returns self with the fg() set to Color::BrightWhite.

§Example
println!("{}", value.bright_white());
source§

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();
source§

fn on_primary(&self) -> Painted<&T>

Returns self with the bg() set to Color::Primary.

§Example
println!("{}", value.on_primary());
source§

fn on_fixed(&self, color: u8) -> Painted<&T>

Returns self with the bg() set to Color::Fixed.

§Example
println!("{}", value.on_fixed(color));
source§

fn on_rgb(&self, r: u8, g: u8, b: u8) -> Painted<&T>

Returns self with the bg() set to Color::Rgb.

§Example
println!("{}", value.on_rgb(r, g, b));
source§

fn on_black(&self) -> Painted<&T>

Returns self with the bg() set to Color::Black.

§Example
println!("{}", value.on_black());
source§

fn on_red(&self) -> Painted<&T>

Returns self with the bg() set to Color::Red.

§Example
println!("{}", value.on_red());
source§

fn on_green(&self) -> Painted<&T>

Returns self with the bg() set to Color::Green.

§Example
println!("{}", value.on_green());
source§

fn on_yellow(&self) -> Painted<&T>

Returns self with the bg() set to Color::Yellow.

§Example
println!("{}", value.on_yellow());
source§

fn on_blue(&self) -> Painted<&T>

Returns self with the bg() set to Color::Blue.

§Example
println!("{}", value.on_blue());
source§

fn on_magenta(&self) -> Painted<&T>

Returns self with the bg() set to Color::Magenta.

§Example
println!("{}", value.on_magenta());
source§

fn on_cyan(&self) -> Painted<&T>

Returns self with the bg() set to Color::Cyan.

§Example
println!("{}", value.on_cyan());
source§

fn on_white(&self) -> Painted<&T>

Returns self with the bg() set to Color::White.

§Example
println!("{}", value.on_white());
source§

fn on_bright_black(&self) -> Painted<&T>

Returns self with the bg() set to Color::BrightBlack.

§Example
println!("{}", value.on_bright_black());
source§

fn on_bright_red(&self) -> Painted<&T>

Returns self with the bg() set to Color::BrightRed.

§Example
println!("{}", value.on_bright_red());
source§

fn on_bright_green(&self) -> Painted<&T>

Returns self with the bg() set to Color::BrightGreen.

§Example
println!("{}", value.on_bright_green());
source§

fn on_bright_yellow(&self) -> Painted<&T>

Returns self with the bg() set to Color::BrightYellow.

§Example
println!("{}", value.on_bright_yellow());
source§

fn on_bright_blue(&self) -> Painted<&T>

Returns self with the bg() set to Color::BrightBlue.

§Example
println!("{}", value.on_bright_blue());
source§

fn on_bright_magenta(&self) -> Painted<&T>

Returns self with the bg() set to Color::BrightMagenta.

§Example
println!("{}", value.on_bright_magenta());
source§

fn on_bright_cyan(&self) -> Painted<&T>

Returns self with the bg() set to Color::BrightCyan.

§Example
println!("{}", value.on_bright_cyan());
source§

fn on_bright_white(&self) -> Painted<&T>

Returns self with the bg() set to Color::BrightWhite.

§Example
println!("{}", value.on_bright_white());
source§

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();
source§

fn bold(&self) -> Painted<&T>

Returns self with the attr() set to Attribute::Bold.

§Example
println!("{}", value.bold());
source§

fn dim(&self) -> Painted<&T>

Returns self with the attr() set to Attribute::Dim.

§Example
println!("{}", value.dim());
source§

fn italic(&self) -> Painted<&T>

Returns self with the attr() set to Attribute::Italic.

§Example
println!("{}", value.italic());
source§

fn underline(&self) -> Painted<&T>

Returns self with the attr() set to Attribute::Underline.

§Example
println!("{}", value.underline());

Returns self with the attr() set to Attribute::Blink.

§Example
println!("{}", value.blink());

Returns self with the attr() set to Attribute::RapidBlink.

§Example
println!("{}", value.rapid_blink());
source§

fn invert(&self) -> Painted<&T>

Returns self with the attr() set to Attribute::Invert.

§Example
println!("{}", value.invert());
source§

fn conceal(&self) -> Painted<&T>

Returns self with the attr() set to Attribute::Conceal.

§Example
println!("{}", value.conceal());
source§

fn strike(&self) -> Painted<&T>

Returns self with the attr() set to Attribute::Strike.

§Example
println!("{}", value.strike());
source§

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();
source§

fn mask(&self) -> Painted<&T>

Returns self with the quirk() set to Quirk::Mask.

§Example
println!("{}", value.mask());
source§

fn wrap(&self) -> Painted<&T>

Returns self with the quirk() set to Quirk::Wrap.

§Example
println!("{}", value.wrap());
source§

fn linger(&self) -> Painted<&T>

Returns self with the quirk() set to Quirk::Linger.

§Example
println!("{}", value.linger());
source§

fn clear(&self) -> Painted<&T>

Returns self with the quirk() set to Quirk::Clear.

§Example
println!("{}", value.clear());
source§

fn bright(&self) -> Painted<&T>

Returns self with the quirk() set to Quirk::Bright.

§Example
println!("{}", value.bright());
source§

fn on_bright(&self) -> Painted<&T>

Returns self with the quirk() set to Quirk::OnBright.

§Example
println!("{}", value.on_bright());
source§

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);
source§

fn new(self) -> Painted<Self>
where Self: Sized,

Create a new Painted with a default Style. Read more
source§

fn paint<S>(&self, style: S) -> Painted<&Self>
where S: Into<Style>,

Apply a style wholesale to self. Any previous style is replaced. Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

source§

impl<T> RuleType for T
where T: Copy + Debug + Eq + Hash + Ord,