livesplit_core/layout/
layout_settings.rs

1use super::{ComponentSettings, GeneralSettings};
2use crate::platform::prelude::*;
3use serde::{Deserialize, Serialize};
4
5/// Describes a whole layout by its settings in a way that can easily be
6/// serialized and deserialized.
7#[derive(Clone, Serialize, Deserialize)]
8pub struct LayoutSettings {
9    /// The settings for all the components.
10    pub components: Vec<ComponentSettings>,
11    /// The general settings of the layout that apply to all components.
12    pub general: GeneralSettings,
13}
14
15#[cfg(feature = "std")]
16impl LayoutSettings {
17    /// Decodes the layout's settings from JSON.
18    pub fn from_json<R>(reader: R) -> serde_json::Result<LayoutSettings>
19    where
20        R: std::io::Read,
21    {
22        serde_json::from_reader(reader)
23    }
24
25    /// Encodes the layout's settings as JSON.
26    pub fn write_json<W>(&self, writer: W) -> serde_json::Result<()>
27    where
28        W: std::io::Write,
29    {
30        serde_json::to_writer(writer, self)
31    }
32}