Skip to main content

ThemePackage

Struct ThemePackage 

Source
pub struct ThemePackage {
    pub file: TokenFile,
    pub fonts: Vec<PackageFont>,
}
Expand description

A token file and the faces it uses.

Fields§

§file: TokenFile§fonts: Vec<PackageFont>

Implementations§

Source§

impl ThemePackage

Source

pub fn new(file: TokenFile) -> ThemePackage

A package of a token file alone.

Source

pub fn add_font( &mut self, family: &str, weight: u16, file_name: &str, bytes: Vec<u8>, )

Adds a face under FONTS_DIR (replacing one of the same file name); the token file lists it when the package is written.

Source

pub fn token_file(&self) -> TokenFile

The token file as written in the package: its faces listed under FONTS_EXTENSION (the entry taken out when it has none), the rest of its root $extensions kept.

Source

pub fn token_file_name(&self) -> String

The name of the token file in the package (<theme>.tokens.json).

Source

pub fn files(&self) -> Vec<(String, Vec<u8>)>

The package’s files: the token file, then each face, by their path in the package.

Source

pub fn read(path: &Path) -> Result<(ThemePackage, Vec<Warning>), Error>

Reads a package: a folder, a .zip archive (with the zip feature), or a lone token file, its faces beside it. What was read otherwise than written comes back as warnings: a face missing or not a font, a second token file in a folder.

Source

pub fn read_dir(dir: &Path) -> Result<(ThemePackage, Vec<Warning>), Error>

Reads a package folder: the token file at its top (the first by name ending in .tokens.json, .tokens.yaml or .tokens.yml) and the faces it lists.

Source

pub fn from_zip(bytes: &[u8]) -> Result<(ThemePackage, Vec<Warning>), Error>

Reads a package from the bytes of a .zip archive: the files at its top, or in its one top folder (an archive of the package’s folder), as ThemePackage::read_dir reads a folder.

Source

pub fn write_dir(&self, dir: &Path) -> Result<PathBuf, Error>

Writes the package as a folder (made if needed): the token file at its top, the faces by their paths. The token file’s path.

Source

pub fn to_zip(&self) -> Result<Vec<u8>, Error>

The package as the bytes of a .zip archive (deflated), its files at its top, dated 1980-01-01 so the same package gives the same bytes.

Source

pub fn write(&self, path: &Path) -> Result<PathBuf, Error>

Writes the package where a user chose to save it: a path ending in .zip becomes an archive; otherwise a package without faces is the lone token file at path, and one with faces a folder named after the theme beside path (<dir>/<theme>/<theme>.tokens.json and its fonts/). The token file’s path, or the archive’s.

Trait Implementations§

Source§

impl Clone for ThemePackage

Source§

fn clone(&self) -> ThemePackage

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 ThemePackage

Source§

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

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

impl PartialEq for ThemePackage

Source§

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

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.