diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-07 05:48:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-07 05:48:48 +0000 |
commit | ef24de24a82fe681581cc130f342363c47c0969a (patch) | |
tree | 0d494f7e1a38b95c92426f58fe6eaa877303a86c /vendor/tabled/src/settings/modify.rs | |
parent | Releasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip |
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/tabled/src/settings/modify.rs')
-rw-r--r-- | vendor/tabled/src/settings/modify.rs | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/vendor/tabled/src/settings/modify.rs b/vendor/tabled/src/settings/modify.rs new file mode 100644 index 000000000..c712a255e --- /dev/null +++ b/vendor/tabled/src/settings/modify.rs @@ -0,0 +1,81 @@ +use crate::{ + grid::records::{ExactRecords, Records}, + settings::{object::Object, CellOption, Settings, TableOption}, +}; + +/// Modify structure provide an abstraction, to be able to apply +/// a set of [`CellOption`]s to the same object. +/// +/// Be aware that the settings are applied all to a cell at a time. +/// So sometimes you may need to make a several calls of [`Modify`] in order to achieve the desired affect. +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +pub struct Modify<O> { + obj: O, +} + +impl<O> Modify<O> { + /// Creates a new [`Modify`] without any options. + pub const fn new(obj: O) -> Self { + Self { obj } + } + + /// A function which combines together [`Modify::new`] and [`Modify::with`] calls. + pub const fn list<M>(obj: O, next: M) -> ModifyList<O, M> { + ModifyList { + obj, + modifiers: next, + } + } + + /// It's a generic function which stores a [`CellOption`]. + /// + /// IMPORTANT: + /// The function *doesn't* changes a [`Table`]. + /// [`Table`] will be changed only after passing [`Modify`] object to [`Table::with`]. + /// + /// [`Table`]: crate::Table + /// [`Table::with`]: crate::Table::with + pub fn with<M>(self, next: M) -> ModifyList<O, M> { + ModifyList { + obj: self.obj, + modifiers: next, + } + } +} + +/// This is a container of [`CellOption`]s which are applied to a set [`Object`]. +#[derive(Debug)] +pub struct ModifyList<O, S> { + obj: O, + modifiers: S, +} + +impl<O, M1> ModifyList<O, M1> { + /// With a generic function which stores a [`CellOption`]. + /// + /// IMPORTANT: + /// The function *doesn't* changes a [`Table`]. + /// [`Table`] will be changed only after passing [`Modify`] object to [`Table::with`]. + /// + /// [`Table`]: crate::Table + /// [`Table::with`]: crate::Table::with + pub fn with<M2>(self, next: M2) -> ModifyList<O, Settings<M1, M2>> { + ModifyList { + obj: self.obj, + modifiers: Settings::new(self.modifiers, next), + } + } +} + +impl<O, M, R, D, C> TableOption<R, D, C> for ModifyList<O, M> +where + O: Object<R>, + M: CellOption<R, C> + Clone, + R: Records + ExactRecords, +{ + fn change(self, records: &mut R, cfg: &mut C, _: &mut D) { + for entity in self.obj.cells(records) { + self.modifiers.clone().change(records, cfg, entity); + } + } +} |