Skip to main content

TokenFile

Struct TokenFile 

Source
pub struct TokenFile {
    pub name: String,
    pub description: Option<String>,
    pub extends: Option<String>,
    pub extensions: Option<Value>,
    pub tokens: BTreeMap<String, RawToken>,
}
Expand description

A token file: a theme, a density overlay or any other layer.

Its tokens are keyed by their dotted path (surface.panel). At the root, $extends names the theme this file builds on (every token not given here comes from it), $description describes the file and $extensions is kept as written.

Fields§

§name: String§description: Option<String>§extends: Option<String>§extensions: Option<Value>

The root $extensions, kept as written.

§tokens: BTreeMap<String, RawToken>

Implementations§

Source§

impl TokenFile

Source

pub fn new(name: impl Into<String>) -> TokenFile

An empty file, to fill by hand.

Source

pub fn parse(name: &str, text: &str) -> Result<TokenFile, Error>

Reads a token file under the given name: JSON when its text starts with {, YAML otherwise (the same tree, with comments).

Source

pub fn parse_cached( name: &str, text: &str, source: &Path, cache: &Cache, ) -> (Result<TokenFile, Error>, Option<CacheError>)

TokenFile::parse for a file read from source, its YAML compiled through a cache (crate::cache): on a hit the JSON the YAML was compiled to is read; on a miss or a stale entry the YAML is parsed (its problems are the error, and are not cached) and its JSON kept. JSON files are read as they are. The second value is the entry that could not be written: the file is read uncached.

Source

pub fn read( name: &str, path: &Path, cache: &Cache, ) -> (Result<TokenFile, Error>, Option<CacheError>)

Reads a token file from disk under the given name, its YAML through a cache (TokenFile::parse_cached).

Source§

impl TokenFile

Source

pub fn to_json(&self) -> Json

The file as DTCG JSON: $description, $extends and $extensions at the root, then each token nested in groups by its path, with its $type, $value, $description and $extensions. TokenFile::parse reads it back as it was.

Source

pub fn to_json_pretty(&self) -> String

TokenFile::to_json, indented for people.

Source§

impl TokenFile

Source

pub fn stamp(&mut self)

Stamps the file with FormatStamp::CURRENT under FORMAT_EXTENSION, keeping the rest of its root $extensions.

Source§

impl TokenFile

Source

pub fn upgrade(&mut self) -> Vec<Warning>

Brings a file to the current contract: reads its stamp (FormatStamp::read) and moves the tokens renamed since the contract it was written for to their new names (RENAMED), the aliases naming them too. What was read otherwise than written comes back as warnings. The stamp itself is left as it was.

Source§

impl TokenFile

Source

pub fn seeds(&self) -> (BTreeMap<String, Seed>, Vec<Warning>)

The colour scales the file gives by their seed (SEEDS_EXTENSION), by scale name, and a warning for each entry that cannot be read (left out: the scale keeps the values under it).

Source

pub fn set_seed(&mut self, scale: &str, seed: Option<Seed>)

Gives a scale by its seed (None takes it out), keeping the rest of the root $extensions.

Source§

impl TokenFile

Source

pub fn set_extension(&mut self, key: &str, value: Option<Json>)

Sets (or, with None, removes) one entry of the root $extensions, keeping the others.

Source

pub fn counterpart_file(&self) -> Option<Result<TokenFile, Error>>

The counterpart this file carries (COUNTERPART_EXTENSION), under its name; None when it carries none, an error when the entry cannot be read.

Source

pub fn set_counterpart_file(&mut self, counterpart: Option<TokenFile>)

Makes this file carry counterpart (COUNTERPART_EXTENSION), each naming the other (VARIANT_OF_EXTENSION); None removes it.

Trait Implementations§

Source§

impl Clone for TokenFile

Source§

fn clone(&self) -> TokenFile

Returns a duplicate 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 TokenFile

Source§

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

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

impl PartialEq for TokenFile

Source§

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

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

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 StructuralPartialEq for TokenFile

Auto Trait Implementations§

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.