1 | use crate::grid::config::Position; |
2 | #[cfg (feature = "std" )] |
3 | use 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 |
8 | pub trait RecordsMut<Text> { |
9 | /// Sets a text to a given cell by index. |
10 | fn set(&mut self, pos: Position, text: Text); |
11 | } |
12 | |
13 | impl<T, Text> RecordsMut<Text> for &'_ mut T |
14 | where |
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" )] |
23 | impl 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" )] |
30 | impl 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 | |