tabled/grid/records/
records_mut.rs

1use crate::grid::config::Position;
2#[cfg(feature = "std")]
3use crate::grid::records::vec_records::{Text, VecRecords};
4
5/// A [`Records`] representation which can modify cell by (row, column) index.
6///
7/// [`Records`]: crate::grid::records::Records
8pub trait RecordsMut<Text> {
9    /// Sets a text to a given cell by index.
10    fn set(&mut self, pos: Position, text: Text);
11}
12
13impl<T, Text> RecordsMut<Text> for &'_ mut T
14where
15    T: RecordsMut<Text>,
16{
17    fn set(&mut self, pos: Position, text: Text) {
18        T::set(self, pos, text)
19    }
20}
21
22#[cfg(feature = "std")]
23impl RecordsMut<String> for VecRecords<Text<String>> {
24    fn set(&mut self, pos: Position, text: String) {
25        self[pos.row][pos.col] = Text::new(text);
26    }
27}
28
29#[cfg(feature = "std")]
30impl RecordsMut<&str> for VecRecords<Text<String>> {
31    fn set(&mut self, p: Position, text: &str) {
32        self[p.row][p.col] = Text::new(text.to_string());
33    }
34}