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/cell_option.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/cell_option.rs')
-rw-r--r-- | vendor/tabled/src/settings/cell_option.rs | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/vendor/tabled/src/settings/cell_option.rs b/vendor/tabled/src/settings/cell_option.rs new file mode 100644 index 000000000..f589ac47f --- /dev/null +++ b/vendor/tabled/src/settings/cell_option.rs @@ -0,0 +1,55 @@ +use crate::grid::{ + config::Entity, + records::{ExactRecords, Records, RecordsMut}, +}; + +/// A trait for configuring a single cell. +/// +/// ~~~~ Where cell represented by 'row' and 'column' indexes. ~~~~ +/// +/// A cell can be targeted by [`Cell`]. +/// +/// [`Cell`]: crate::object::Cell +pub trait CellOption<R, C> { + /// Modification function of a single cell. + fn change(self, records: &mut R, cfg: &mut C, entity: Entity); +} + +#[cfg(feature = "std")] +impl<R, C> CellOption<R, C> for String +where + R: Records + ExactRecords + RecordsMut<String>, +{ + fn change(self, records: &mut R, cfg: &mut C, entity: Entity) { + (&self).change(records, cfg, entity); + } +} + +#[cfg(feature = "std")] +impl<R, C> CellOption<R, C> for &String +where + R: Records + ExactRecords + RecordsMut<String>, +{ + fn change(self, records: &mut R, _: &mut C, entity: Entity) { + let count_rows = records.count_rows(); + let count_cols = records.count_columns(); + + for pos in entity.iter(count_rows, count_cols) { + records.set(pos, self.clone()); + } + } +} + +impl<'a, R, C> CellOption<R, C> for &'a str +where + R: Records + ExactRecords + RecordsMut<&'a str>, +{ + fn change(self, records: &mut R, _: &mut C, entity: Entity) { + let count_rows = records.count_rows(); + let count_cols = records.count_columns(); + + for pos in entity.iter(count_rows, count_cols) { + records.set(pos, self); + } + } +} |