Struct Scheme

Source
pub struct Scheme {
    pub scheme: String,
    pub author: String,
    pub slug: String,
    pub colors: BTreeMap<BaseIndex, RgbColor>,
}
Expand description

type representing a base16 scheme

§Example

use base16_color_scheme::{Scheme, Template};

let template = Template::new("\
{{scheme-name}} {{scheme-slug}} {{scheme-author}}
{{base00-hex}} {{base00-hex-bgr}}
{{base00-hex-r}} {{base00-hex-g}} {{base00-hex-b}}
{{base00-rgb-r}} {{base00-rgb-g}} {{base00-rgb-b}}
{{base00-dec-r}} {{base00-dec-g}} {{base00-dec-b}}
{{base00-hsl-h}} {{base00-hsl-s}} {{base00-hsl-l}}").unwrap();

let mut scheme: Scheme = serde_yaml::from_str(r#"
scheme: "Scheme Name"
author: "Scheme Author"
base00: "7cafc2"
"#).unwrap();
scheme = scheme.create_slug();

println!("{}", template.render(&scheme));
assert_eq!(
    template.render(&scheme),
    "\
Scheme Name scheme-name Scheme Author
7cafc2 c2af7c
7c af c2
124 175 194
0.49 0.69 0.76
196.29 0.36 0.62");

§Serialization / Deserialization

When deserializing Scheme requires the fields scheme and author, ignores the field scheme-slug, and accepts any number of fields between base00 and baseFF, (any combination of uppercase and lowercase, so baseab, baseAB, and baseAb all work.) though for a normal base16 theme it should have at least base00 to base0F.

Because scheme-slug is not created while deserialization it has to be inserted manually. Either by setting Scheme::slug manually, or using Scheme::create_slug.

When serializing Scheme it first serializes Scheme::scheme and Scheme::author then ignores Scheme::slug as per specification and afterwards serializes all colors contained in Scheme::colors ordered by the field number.
(base00, base01, base05 etc.)

Fields§

§scheme: String§author: String§slug: String§colors: BTreeMap<BaseIndex, RgbColor>

Implementations§

Source§

impl Scheme

Source

pub fn scheme_name(&self) -> &str

Source

pub fn scheme_slug(&self) -> &str

Source

pub fn create_slug(self) -> Self

Fill Self::slug based on Self::scheme.

see create_slug

Source

pub fn scheme_author(&self) -> &str

Source

pub fn color(&self, _: ColorField) -> Option<RgbColorFormatter>

Look up the field in Self::color and return a formatter for it.
(If the field exists.)

Trait Implementations§

Source§

impl Clone for Scheme

Source§

fn clone(&self) -> Scheme

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Content for Scheme

Source§

fn is_truthy(&self) -> bool

Marks whether this content is truthy. Used when attempting to render a section.
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_field_escaped<E: Encoder>( &self, _hash: u64, name: &str, encoder: &mut E, ) -> Result<bool, E::Error>

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

fn render_field_inverse<C, E>( &self, _hash: u64, name: &str, section: Section<'_, C>, encoder: &mut E, ) -> Result<bool, E::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§

fn render_escaped<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_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_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§

impl Debug for Scheme

Source§

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

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

impl Default for Scheme

Source§

fn default() -> Scheme

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Scheme

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

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

impl Ord for Scheme

Source§

fn cmp(&self, other: &Scheme) -> 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,

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

impl PartialEq for Scheme

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Scheme

Source§

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

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

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

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Scheme

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

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

impl Eq for Scheme

Source§

impl StructuralPartialEq for Scheme

Auto Trait Implementations§

§

impl Freeze for Scheme

§

impl RefUnwindSafe for Scheme

§

impl Send for Scheme

§

impl Sync for Scheme

§

impl Unpin for Scheme

§

impl UnwindSafe for Scheme

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,