1use crate::grid::config::Position;
2#[cfg(feature = "std")]
3use crate::grid::records::vec_records::{CellInfo, 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<CellInfo<String>> {
24 fn set(&mut self, (row: usize, col: usize): Position, text: String) {
25 self[row][col] = CellInfo::new(text);
26 }
27}
28
29#[cfg(feature = "std")]
30impl RecordsMut<&str> for VecRecords<CellInfo<String>> {
31 fn set(&mut self, (row: usize, col: usize): Position, text: &str) {
32 self[row][col] = CellInfo::new(text:text.to_string());
33 }
34}
35