pub struct RgbColorFormatter {
    pub color: RgbColor,
    pub format: Format,
}
Expand description

formatter that formats a color according to the specification

This formatter contains a color and a specifier in what format this color should be formatted.

Example

use base16_color_scheme::{
    scheme::{RgbColor, RgbColorFormatter},
    template::color_field::{Dec, Format, Hex, Hsl, Rgb},
};

let color = RgbColor([0x7c, 0xaf, 0xc2]);

// This macro is used to test the result of format!("{}") in a much more readable fashion
rgb_formatter_eq! {
    color,
    Format::Hex(Hex::Rgb), "7cafc2";
    Format::Hex(Hex::R),   "7c";
    Format::Hex(Hex::G),   "af";
    Format::Hex(Hex::B),   "c2";
    Format::Hex(Hex::Bgr), "c2af7c";
    Format::Rgb(Rgb::R),   "124";
    Format::Rgb(Rgb::G),   "175";
    Format::Rgb(Rgb::B),   "194";
    Format::Dec(Dec::R),   "0.49";
    Format::Dec(Dec::G),   "0.69";
    Format::Dec(Dec::B),   "0.76";
    Format::Hsl(Hsl::H),   "196.29";
    Format::Hsl(Hsl::S),   "0.36";
    Format::Hsl(Hsl::L),   "0.62";
}

Fields§

§color: RgbColor§format: Format

Trait Implementations§

source§

impl Clone for RgbColorFormatter

source§

fn clone(&self) -> RgbColorFormatter

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 Content for RgbColorFormatter

source§

fn is_truthy(&self) -> bool

Marks whether this content is truthy. Used when attempting to render a section.
source§

fn render_escaped<E: Encoder>(&self, encoder: &mut E) -> Result<(), E::Error>

Renders self as a variable to the encoder. Read more
source§

fn capacity_hint(&self, _tpl: &Template<'_>) -> usize

How much capacity is likely required for all the data in this Content for a given Template.
source§

fn render_unescaped<E>( &self, encoder: &mut E ) -> Result<(), <E as Encoder>::Error>where E: Encoder,

Renders self as a variable to the encoder. Read more
source§

fn render_section<C, E>( &self, section: Section<'_, C>, encoder: &mut E ) -> Result<(), <E as Encoder>::Error>where C: ContentSequence, E: Encoder,

Render a section with self.
source§

fn render_inverse<C, E>( &self, section: Section<'_, C>, encoder: &mut E ) -> Result<(), <E as Encoder>::Error>where C: ContentSequence, E: Encoder,

Render a section with self.
source§

fn render_field_escaped<E>( &self, _hash: u64, _name: &str, _encoder: &mut E ) -> Result<bool, <E as Encoder>::Error>where E: Encoder,

Render a field by the hash or string of its name. Read more
source§

fn render_field_unescaped<E>( &self, _hash: u64, _name: &str, _encoder: &mut E ) -> Result<bool, <E as Encoder>::Error>where E: Encoder,

Render a field by the hash or string of its name. Read more
source§

fn render_field_section<C, E>( &self, _hash: u64, _name: &str, _section: Section<'_, C>, _encoder: &mut E ) -> Result<bool, <E as Encoder>::Error>where C: ContentSequence, E: Encoder,

Render a field by the hash or string of its name, as a section. If successful, returns true if the field exists in this content, otherwise false.
source§

fn render_field_inverse<C, E>( &self, _hash: u64, _name: &str, _section: Section<'_, C>, _encoder: &mut E ) -> Result<bool, <E as Encoder>::Error>where C: ContentSequence, E: Encoder,

Render a field, by the hash of or string its name, as an inverse section. If successful, returns true if the field exists in this content, otherwise false.
source§

impl Debug for RgbColorFormatter

source§

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

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

impl Display for RgbColorFormatter

source§

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

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

impl Hash for RgbColorFormatter

source§

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

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 RgbColorFormatter

source§

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

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

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

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

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

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

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

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

impl PartialEq<RgbColorFormatter> for RgbColorFormatter

source§

fn eq(&self, other: &RgbColorFormatter) -> 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<RgbColorFormatter> for RgbColorFormatter

source§

fn partial_cmp(&self, other: &RgbColorFormatter) -> 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 Copy for RgbColorFormatter

source§

impl Eq for RgbColorFormatter

source§

impl StructuralEq for RgbColorFormatter

source§

impl StructuralPartialEq for RgbColorFormatter

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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> ToOwned for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.