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 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 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) -> 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<Scheme> for Scheme

source§

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

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 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 StructuralEq for Scheme

source§

impl StructuralPartialEq for Scheme

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, 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.
source§

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