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
impl ThemePackage
Sourcepub fn new(file: TokenFile) -> ThemePackage
pub fn new(file: TokenFile) -> ThemePackage
A package of a token file alone.
Sourcepub fn add_font(
&mut self,
family: &str,
weight: u16,
file_name: &str,
bytes: Vec<u8>,
)
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.
Sourcepub fn token_file(&self) -> TokenFile
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.
Sourcepub fn token_file_name(&self) -> String
pub fn token_file_name(&self) -> String
The name of the token file in the package
(<theme>.tokens.json).
Sourcepub fn files(&self) -> Vec<(String, Vec<u8>)>
pub fn files(&self) -> Vec<(String, Vec<u8>)>
The package’s files: the token file, then each face, by their path in the package.
Sourcepub fn read(path: &Path) -> Result<(ThemePackage, Vec<Warning>), Error>
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.
Sourcepub fn read_dir(dir: &Path) -> Result<(ThemePackage, Vec<Warning>), Error>
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.
Sourcepub fn from_zip(bytes: &[u8]) -> Result<(ThemePackage, Vec<Warning>), Error>
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.
Sourcepub fn write_dir(&self, dir: &Path) -> Result<PathBuf, Error>
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.
Sourcepub fn to_zip(&self) -> Result<Vec<u8>, Error>
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.
Sourcepub fn write(&self, path: &Path) -> Result<PathBuf, Error>
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
impl Clone for ThemePackage
Source§fn clone(&self) -> ThemePackage
fn clone(&self) -> ThemePackage
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more