1use std::fmt::Display;
4
5use crate::{App, AppData, FQLType};
6
7pub trait Editor {
8 fn add(&mut self, new_data: AppData);
9 fn remove(&mut self, index: usize);
10 fn insert(&mut self, index: usize, new_data: AppData);
11 fn replace(&mut self, index: usize, new_data: AppData);
12 fn update<T: Display>(&mut self, index: usize, key: T, new_value: FQLType);
13}
14
15impl Editor for App {
16 fn replace(&mut self, index: usize, new_data: AppData) {
25 self.data.remove(index);
26 self.data.insert(index, new_data);
27 }
28
29 fn insert(&mut self, index: usize, new_data: AppData) {
31 self.data.insert(index, new_data);
32 }
33
34 fn remove(&mut self, index: usize) {
42 self.data.remove(index);
43 }
44
45 fn update<T: Display>(&mut self, index: usize, key: T, new_value: FQLType) {
46 let mut new_data = self.data.remove(index);
47 new_data.insert(key.to_string(), new_value);
48 self.data.insert(index, new_data);
49 }
50
51 fn add(&mut self, new_data: AppData) {
53 self.data.push(new_data);
54 }
55}