1use crate::settings::TableOption;
2
3#[cfg(feature = "std")]
4use crate::grid::config::Entity;
5#[cfg(feature = "std")]
6use crate::settings::CellOption;
7
8/// Settings is a combinator of [`TableOption`]s.
9#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
10pub struct Settings<A = EmptySettings, B = EmptySettings>(A, B);
11
12impl Default for Settings<EmptySettings, EmptySettings> {
13 fn default() -> Self {
14 Self(EmptySettings, EmptySettings)
15 }
16}
17
18impl Settings<(), ()> {
19 /// Creates an empty list.
20 pub const fn empty() -> Settings<EmptySettings, EmptySettings> {
21 Settings(EmptySettings, EmptySettings)
22 }
23}
24
25impl<A, B> Settings<A, B> {
26 /// Creates a new combinator.
27 pub const fn new(settings1: A, settings2: B) -> Settings<A, B> {
28 Settings(settings1, settings2)
29 }
30
31 /// Add an option to a combinator.
32 pub const fn with<C>(self, settings: C) -> Settings<Self, C> {
33 Settings(self, settings)
34 }
35}
36
37#[cfg(feature = "std")]
38impl<R, C, A, B> CellOption<R, C> for Settings<A, B>
39where
40 A: CellOption<R, C>,
41 B: CellOption<R, C>,
42{
43 fn change(self, records: &mut R, cfg: &mut C, entity: Entity) {
44 self.0.change(records, cfg, entity);
45 self.1.change(records, cfg, entity);
46 }
47}
48
49impl<R, D, C, A, B> TableOption<R, D, C> for Settings<A, B>
50where
51 A: TableOption<R, D, C>,
52 B: TableOption<R, D, C>,
53{
54 fn change(self, records: &mut R, cfg: &mut C, dims: &mut D) {
55 self.0.change(records, cfg, dimension:dims);
56 self.1.change(records, cfg, dimension:dims);
57 }
58}
59
60/// A marker structure to be able to create an empty [`Settings`].
61#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
62pub struct EmptySettings;
63
64#[cfg(feature = "std")]
65impl<R, C> CellOption<R, C> for EmptySettings {
66 fn change(self, _: &mut R, _: &mut C, _: Entity) {}
67}
68
69impl<R, D, C> TableOption<R, D, C> for EmptySettings {
70 fn change(self, _: &mut R, _: &mut C, _: &mut D) {}
71}
72