use crate::{DisplayInfo, RustConstructorResource};
use std::{any::Any, fmt::Debug};
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct PageData {
pub forced_update: bool,
pub change_page_updated: bool,
pub enter_page_updated: bool,
pub tags: Vec<[String; 2]>,
}
impl RustConstructorResource for PageData {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn display_display_info(&self) -> Option<DisplayInfo> {
None
}
fn modify_display_info(&mut self, _display_info: DisplayInfo) {}
fn display_tags(&self) -> Vec<[String; 2]> {
self.tags.clone()
}
fn modify_tags(&mut self, tags: &[[String; 2]], replace: bool) {
if replace {
self.tags = tags.to_owned();
} else {
for tag in tags {
if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
self.tags.remove(index);
};
}
self.tags.extend(tags.iter().cloned());
};
}
}
impl Default for PageData {
fn default() -> Self {
PageData {
forced_update: true,
change_page_updated: false,
enter_page_updated: false,
tags: Vec::new(),
}
}
}
impl PageData {
#[inline]
pub fn forced_update(mut self, forced_update: bool) -> Self {
self.forced_update = forced_update;
self
}
#[inline]
pub fn tags(mut self, tags: &[[String; 2]], replace: bool) -> Self {
if replace {
self.tags = tags.to_owned();
} else {
for tag in tags {
if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
self.tags.remove(index);
};
}
self.tags.extend(tags.iter().cloned());
};
self
}
}
#[derive(Debug, Clone, PartialEq, PartialOrd)]
pub struct Variable<T> {
pub value: Option<T>,
pub tags: Vec<[String; 2]>,
}
impl<T: Debug + Send + Sync + 'static> RustConstructorResource for Variable<T> {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn display_display_info(&self) -> Option<DisplayInfo> {
None
}
fn modify_display_info(&mut self, _display_info: DisplayInfo) {}
fn display_tags(&self) -> Vec<[String; 2]> {
self.tags.clone()
}
fn modify_tags(&mut self, tags: &[[String; 2]], replace: bool) {
if replace {
self.tags = tags.to_owned();
} else {
for tag in tags {
if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
self.tags.remove(index);
};
}
self.tags.extend(tags.iter().cloned());
};
}
}
impl<T> Default for Variable<T> {
fn default() -> Self {
Variable {
value: None,
tags: Vec::new(),
}
}
}
impl<T> Variable<T> {
#[inline]
pub fn value(mut self, value: Option<T>) -> Self {
self.value = value;
self
}
#[inline]
pub fn tags(mut self, tags: &[[String; 2]], replace: bool) -> Self {
if replace {
self.tags = tags.to_owned();
} else {
for tag in tags {
if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
self.tags.remove(index);
};
}
self.tags.extend(tags.iter().cloned());
};
self
}
}
#[derive(Debug, Default, Clone, PartialEq, PartialOrd)]
pub struct SplitTime {
pub time: [u128; 2],
pub tags: Vec<[String; 2]>,
}
impl RustConstructorResource for SplitTime {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn display_display_info(&self) -> Option<DisplayInfo> {
None
}
fn modify_display_info(&mut self, _display_info: DisplayInfo) {}
fn display_tags(&self) -> Vec<[String; 2]> {
self.tags.clone()
}
fn modify_tags(&mut self, tags: &[[String; 2]], replace: bool) {
if replace {
self.tags = tags.to_owned();
} else {
for tag in tags {
if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
self.tags.remove(index);
};
}
self.tags.extend(tags.iter().cloned());
};
}
}
impl SplitTime {
#[inline]
pub fn tags(mut self, tags: &[[String; 2]], replace: bool) -> Self {
if replace {
self.tags = tags.to_owned();
} else {
for tag in tags {
if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
self.tags.remove(index);
};
}
self.tags.extend(tags.iter().cloned());
};
self
}
}