use super::{NodeId, StaticGraftCut};
pub type Graft = StaticGraftCut;
#[derive(Clone, Copy, Debug)]
pub struct GraftRange<T> {
start: T,
end: T,
}
#[derive(Clone, Copy, Debug)]
pub struct GraftSubtree<T>(T);
#[derive(Clone, Copy, Debug)]
pub struct GraftSelection<T>(T);
pub const fn graft<T: Copy>(target: T) -> GraftSelection<T> {
GraftSelection(target)
}
pub const fn range<T: Copy>(start: T, end: T) -> GraftRange<T> {
GraftRange { start, end }
}
pub const fn subtree<T: Copy>(target: T) -> GraftSubtree<T> {
GraftSubtree(target)
}
macro_rules! replacements {
($ty:ty, $single:ident, $range:ident) => {
impl GraftSelection<$ty> {
pub const fn with(self, replacement: $ty) -> Graft {
Graft::$single(self.0, replacement, false)
}
}
impl GraftSelection<GraftRange<$ty>> {
pub const fn with(self, replacement: $ty) -> Graft {
Graft::$range(self.0.start, self.0.end, replacement, false)
}
}
impl GraftSelection<GraftSubtree<$ty>> {
pub const fn with(self, replacement: $ty) -> Graft {
Graft::$single(self.0.0, replacement, true)
}
}
};
}
replacements!(NodeId, from_ids, from_id_range);
replacements!(&'static str, new, new_range);