livesplit_core/component/separator.rs
1//! Provides the Separator Component and relevant types for using it. The
2//! Separator Component is a simple component that only serves to render
3//! separators between components.
4
5use crate::settings::{SettingsDescription, Value};
6use serde::{Deserialize, Serialize};
7
8/// The Separator Component is a simple component that only serves to render
9/// separators between components.
10#[derive(Default, Clone)]
11pub struct Component;
12
13/// The state object describes the information to visualize for this component.
14#[derive(Default, Serialize, Deserialize)]
15pub struct State;
16
17#[cfg(feature = "std")]
18impl State {
19 /// Encodes the state object's information as JSON.
20 pub fn write_json<W>(&self, writer: W) -> serde_json::Result<()>
21 where
22 W: std::io::Write,
23 {
24 serde_json::to_writer(writer, self)
25 }
26}
27
28impl Component {
29 /// Creates a new Separator Component.
30 pub fn new() -> Self {
31 Default::default()
32 }
33
34 /// Accesses the name of the component.
35 pub const fn name(&self) -> &'static str {
36 "Separator"
37 }
38
39 /// Updates the component's state.
40 pub fn update_state(&self, _state: &mut State) {}
41
42 /// Calculates the component's state.
43 pub const fn state(&self) -> State {
44 State
45 }
46
47 /// Accesses a generic description of the settings available for this
48 /// component and their current values.
49 pub fn settings_description(&self) -> SettingsDescription {
50 SettingsDescription::default()
51 }
52
53 /// Sets a setting's value by its index to the given value.
54 ///
55 /// # Panics
56 ///
57 /// This panics if the type of the value to be set is not compatible with
58 /// the type of the setting's value. A panic can also occur if the index of
59 /// the setting provided is out of bounds.
60 #[allow(clippy::needless_pass_by_value)]
61 pub fn set_value(&mut self, _index: usize, _value: Value) {}
62}