use std::fmt::Display;
use crate::{App, AppData, FQLType};
pub trait Editor {
fn add(&mut self, new_data: AppData);
fn remove(&mut self, index: usize);
fn insert(&mut self, index: usize, new_data: AppData);
fn replace(&mut self, index: usize, new_data: AppData);
fn update<T: Display>(&mut self, index: usize, key: T, new_value: FQLType);
}
impl Editor for App {
fn replace(&mut self, index: usize, new_data: AppData) {
self.data.remove(index);
self.data.insert(index, new_data);
}
fn insert(&mut self, index: usize, new_data: AppData) {
self.data.insert(index, new_data);
}
fn remove(&mut self, index: usize) {
self.data.remove(index);
}
fn update<T: Display>(&mut self, index: usize, key: T, new_value: FQLType) {
let mut new_data = self.data.remove(index);
new_data.insert(key.to_string(), new_value);
self.data.insert(index, new_data);
}
fn add(&mut self, new_data: AppData) {
self.data.push(new_data);
}
}