2022-10-28 04:58:47 +00:00
|
|
|
use crate::arena::ElementId;
|
2021-08-22 21:08:25 +00:00
|
|
|
|
2022-11-09 03:39:37 +00:00
|
|
|
#[derive(Debug)]
|
2022-11-09 18:58:11 +00:00
|
|
|
pub struct Mutations<'a> {
|
2022-11-09 03:39:37 +00:00
|
|
|
pub subtree: usize,
|
|
|
|
pub template_mutations: Vec<Mutation<'a>>,
|
2022-11-12 02:29:27 +00:00
|
|
|
pub edits: Vec<Mutation<'a>>,
|
2022-10-28 04:58:47 +00:00
|
|
|
}
|
2022-11-09 03:39:37 +00:00
|
|
|
|
2022-11-09 18:58:11 +00:00
|
|
|
impl<'a> Mutations<'a> {
|
2022-11-09 03:39:37 +00:00
|
|
|
pub fn new(subtree: usize) -> Self {
|
|
|
|
Self {
|
|
|
|
subtree,
|
2022-11-12 02:29:27 +00:00
|
|
|
edits: Vec::new(),
|
2022-11-09 03:39:37 +00:00
|
|
|
template_mutations: Vec::new(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-09 18:58:11 +00:00
|
|
|
impl<'a> std::ops::Deref for Mutations<'a> {
|
2022-11-09 03:39:37 +00:00
|
|
|
type Target = Vec<Mutation<'a>>;
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
2022-11-12 02:29:27 +00:00
|
|
|
&self.edits
|
2022-11-09 03:39:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-09 18:58:11 +00:00
|
|
|
impl std::ops::DerefMut for Mutations<'_> {
|
2022-11-09 03:39:37 +00:00
|
|
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
2022-11-12 02:29:27 +00:00
|
|
|
&mut self.edits
|
2022-11-09 03:39:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
each subtree has its own numbering scheme
|
|
|
|
*/
|
2022-10-20 16:56:09 +00:00
|
|
|
|
2022-11-12 02:29:27 +00:00
|
|
|
#[derive(Debug, PartialEq, Eq)]
|
2022-10-28 04:58:47 +00:00
|
|
|
pub enum Mutation<'a> {
|
|
|
|
SetAttribute {
|
2022-11-03 00:29:18 +00:00
|
|
|
name: &'a str,
|
2022-10-28 04:58:47 +00:00
|
|
|
value: &'a str,
|
|
|
|
id: ElementId,
|
|
|
|
},
|
2022-10-20 16:56:09 +00:00
|
|
|
|
2022-10-28 04:58:47 +00:00
|
|
|
LoadTemplate {
|
|
|
|
name: &'static str,
|
|
|
|
index: usize,
|
|
|
|
},
|
|
|
|
|
2022-11-02 01:42:29 +00:00
|
|
|
SaveTemplate {
|
|
|
|
name: &'static str,
|
|
|
|
m: usize,
|
|
|
|
},
|
|
|
|
|
2022-10-28 04:58:47 +00:00
|
|
|
HydrateText {
|
|
|
|
path: &'static [u8],
|
|
|
|
value: &'a str,
|
|
|
|
id: ElementId,
|
|
|
|
},
|
|
|
|
|
|
|
|
SetText {
|
|
|
|
value: &'a str,
|
|
|
|
id: ElementId,
|
|
|
|
},
|
|
|
|
|
|
|
|
ReplacePlaceholder {
|
2022-11-02 01:42:29 +00:00
|
|
|
m: usize,
|
2022-11-02 08:00:37 +00:00
|
|
|
path: &'static [u8],
|
2022-10-28 04:58:47 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
AssignId {
|
|
|
|
path: &'static [u8],
|
|
|
|
id: ElementId,
|
|
|
|
},
|
|
|
|
|
|
|
|
// Take the current element and replace it with the element with the given id.
|
|
|
|
Replace {
|
|
|
|
id: ElementId,
|
2022-11-04 00:34:42 +00:00
|
|
|
m: usize,
|
2022-10-28 04:58:47 +00:00
|
|
|
},
|
2022-11-02 01:42:29 +00:00
|
|
|
|
|
|
|
CreateElement {
|
|
|
|
name: &'a str,
|
|
|
|
namespace: Option<&'a str>,
|
|
|
|
id: ElementId,
|
|
|
|
},
|
|
|
|
|
|
|
|
CreateText {
|
|
|
|
value: &'a str,
|
|
|
|
},
|
|
|
|
|
2022-11-04 00:34:42 +00:00
|
|
|
CreatePlaceholder {
|
|
|
|
id: ElementId,
|
|
|
|
},
|
2022-11-02 01:42:29 +00:00
|
|
|
|
|
|
|
AppendChildren {
|
|
|
|
m: usize,
|
|
|
|
},
|
2021-08-22 21:08:25 +00:00
|
|
|
}
|