Struct base16_color_scheme::scheme::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
§slug: String
§colors: BTreeMap<BaseIndex, RgbColor>
Implementations§
source§impl Scheme
impl Scheme
pub fn scheme_name(&self) -> &str
pub fn scheme_slug(&self) -> &str
sourcepub fn create_slug(self) -> Self
pub fn create_slug(self) -> Self
Fill Self::slug
based on Self::scheme
.
see create_slug
sourcepub fn color(&self, _: ColorField) -> Option<RgbColorFormatter>
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 Content for Scheme
impl Content for Scheme
source§fn is_truthy(&self) -> bool
fn is_truthy(&self) -> bool
source§fn capacity_hint(&self, _tpl: &Template<'_>) -> usize
fn capacity_hint(&self, _tpl: &Template<'_>) -> usize
Content
for a given Template
.source§fn render_field_escaped<E: Encoder>(
&self,
_hash: u64,
name: &str,
encoder: &mut E
) -> Result<bool, E::Error>
fn render_field_escaped<E: Encoder>( &self, _hash: u64, name: &str, encoder: &mut E ) -> Result<bool, E::Error>
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,
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,
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,
fn render_escaped<E>( &self, _encoder: &mut E ) -> Result<(), <E as Encoder>::Error>where E: Encoder,
source§fn render_unescaped<E>(
&self,
encoder: &mut E
) -> Result<(), <E as Encoder>::Error>where
E: Encoder,
fn render_unescaped<E>( &self, encoder: &mut E ) -> Result<(), <E as Encoder>::Error>where E: Encoder,
source§fn render_section<C, E>(
&self,
section: Section<'_, C>,
encoder: &mut E
) -> Result<(), <E as Encoder>::Error>where
C: ContentSequence,
E: Encoder,
fn render_section<C, E>( &self, section: Section<'_, C>, encoder: &mut E ) -> Result<(), <E as Encoder>::Error>where C: ContentSequence, E: Encoder,
source§fn render_inverse<C, E>(
&self,
section: Section<'_, C>,
encoder: &mut E
) -> Result<(), <E as Encoder>::Error>where
C: ContentSequence,
E: Encoder,
fn render_inverse<C, E>( &self, section: Section<'_, C>, encoder: &mut E ) -> Result<(), <E as Encoder>::Error>where C: ContentSequence, E: Encoder,
source§fn render_field_unescaped<E>(
&self,
_hash: u64,
_name: &str,
_encoder: &mut E
) -> Result<bool, <E as Encoder>::Error>where
E: Encoder,
fn render_field_unescaped<E>( &self, _hash: u64, _name: &str, _encoder: &mut E ) -> Result<bool, <E as Encoder>::Error>where E: Encoder,
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,
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,
true
if the field exists in this content, otherwise false
.source§impl<'de> Deserialize<'de> for Scheme
impl<'de> Deserialize<'de> for Scheme
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
source§impl Ord for Scheme
impl Ord for Scheme
source§impl PartialEq<Scheme> for Scheme
impl PartialEq<Scheme> for Scheme
source§impl PartialOrd<Scheme> for Scheme
impl PartialOrd<Scheme> for Scheme
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more