1
0
Fork 0
forked from alemi/upub

feat(apb): allow editing inner nodes

actually only if it implements Clone but whatever good enough for now
This commit is contained in:
əlemi 2024-05-01 17:46:54 +02:00
parent 7439b815be
commit 71c3c54859
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -16,6 +16,9 @@ impl<T : super::Base> From<Option<T>> for Node<T> {
}
}
// TODO how do i move out of the box for a moment? i need to leave it uninitialized while i update
// the value and then put it back, i think it should be safe to do so! but i'm not sure how, so i'm
// using a clone (expensive but simple solution)
impl<T : super::Base + Clone> Iterator for Node<T> {
type Item = T;
@ -31,6 +34,14 @@ impl<T : super::Base + Clone> Iterator for Node<T> {
}
}
impl<T : super::Base + Clone> Node<T> {
pub fn update(&mut self, builder: impl FnOnce(T) -> T) {
if let Node::Object(x) = self {
*x = Box::new(builder((**x).clone()));
}
}
}
impl<T : super::Base> Node<T> {
/// return reference to embedded object (or last if many are present)
pub fn get(&self) -> Option<&T> {