wavedrom/
skin.rs

1//! Module with a WaveDrom skin
2use serde::{Deserialize, Serialize};
3
4use crate::svg::options::{PartialRenderOptions, RenderOptions};
5use crate::PathAssembleOptions;
6
7/// The definition for a WaveDrom skin.
8/// 
9/// This is a JSON file that defines options for how to assemble and render a WaveDrom figure.
10#[derive(Debug, Clone, Deserialize, Serialize)]
11pub struct Skin {
12    /// Assemble options given as an optional [`PathAssembleOptions`]
13    pub assemble: Option<PathAssembleOptions>,
14    /// Render options given as an optional subset of a [`RenderOptions`]
15    pub render: Option<PartialRenderOptions>,
16}
17
18
19impl Skin {
20    /// Generate a set of options from the [`Skin`].
21    ///
22    /// If some options was not specified by the skin it is set to the default value.
23    pub fn options(self) -> (PathAssembleOptions, RenderOptions) {
24        (self.assemble.unwrap_or_default(), self.render.map_or_else(RenderOptions::default, RenderOptions::from))
25    }
26
27    /// Parse a [`Skin`] from a human-friendly / JSON5 file.
28    #[cfg(feature = "json5")]
29    #[inline]
30    pub fn from_json5(s: &str) -> Result<Self, json5::Error> {
31        json5::from_str(s)
32    }
33
34    /// Parse a [`Skin`] from a JSON file.
35    #[cfg(feature = "serde_json")]
36    #[inline]
37    pub fn from_json(s: &str) -> Result<Self, serde_json::error::Error> {
38        serde_json::from_str(s)
39    }
40}