use crate::ast::AstAlloc;
pub trait Combine {
fn combine(left: Self, right: Self) -> Self;
}
pub trait CombineAlloc<'ast> {
fn combine(alloc: &'ast AstAlloc, left: Self, right: Self) -> Self;
}
impl<T: Combine> Combine for Option<T> {
fn combine(left: Self, right: Self) -> Self {
match (left, right) {
(None, None) => None,
(None, Some(x)) | (Some(x), None) => Some(x),
(Some(left), Some(right)) => Some(Combine::combine(left, right)),
}
}
}
impl<'ast, T: CombineAlloc<'ast>> CombineAlloc<'ast> for Option<T> {
fn combine(alloc: &'ast AstAlloc, left: Self, right: Self) -> Self {
match (left, right) {
(None, None) => None,
(None, Some(x)) | (Some(x), None) => Some(x),
(Some(left), Some(right)) => Some(CombineAlloc::combine(alloc, left, right)),
}
}
}