skribble_core/config/
style.rs

1use serde::Deserialize;
2use serde::Serialize;
3use typed_builder::TypedBuilder;
4
5use crate::Error;
6use crate::Options;
7use crate::Result;
8
9/// The style configuration which can also use the builder pattern.
10#[derive(Serialize, Deserialize, TypedBuilder, Default, Debug, PartialEq)]
11#[serde(rename_all = "camelCase")]
12pub struct StyleConfig {
13  /// The general options.
14  pub options: Options,
15}
16
17impl StyleConfig {
18  pub fn from_json(json: &str) -> Result<Self> {
19    let config: Self =
20      serde_json::from_str(json).map_err(|source| Error::InvalidConfig { source })?;
21    Ok(config)
22  }
23}
24
25#[cfg(test)]
26mod tests {
27  use super::*;
28
29  #[test]
30  fn check_config_can_serialize() {
31    let config: StyleConfig = serde_json::from_str(include_str!("default.json")).unwrap();
32    let json = serde_json::to_string(&config).unwrap();
33    assert_eq!(config, serde_json::from_str(&json).unwrap());
34  }
35
36  #[test]
37  fn default_config() {
38    insta::assert_json_snapshot!(StyleConfig::default());
39  }
40}