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:
parent
7439b815be
commit
71c3c54859
1 changed files with 11 additions and 0 deletions
|
@ -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> {
|
impl<T : super::Base + Clone> Iterator for Node<T> {
|
||||||
type Item = 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> {
|
impl<T : super::Base> Node<T> {
|
||||||
/// return reference to embedded object (or last if many are present)
|
/// return reference to embedded object (or last if many are present)
|
||||||
pub fn get(&self) -> Option<&T> {
|
pub fn get(&self) -> Option<&T> {
|
||||||
|
|
Loading…
Reference in a new issue