use std::rc::Rc;
use crate::parser::tree::{ParseContext, ParseTree};
#[derive(Debug, Clone)]
pub(crate) enum Child<C>
where
C: ParseContext,
{
Contains(ParseTree<C>),
ByRef(Rc<ParseTree<C>>),
}
impl<C> Child<C>
where
C: ParseContext,
{
pub fn as_tree(&self) -> &ParseTree<C> {
match self {
Self::Contains(tree) => tree,
Self::ByRef(ptr) => ptr,
}
}
pub fn as_tree_mut(&mut self) -> Option<&mut ParseTree<C>> {
match self {
Self::Contains(tree) => Some(tree),
Self::ByRef(_) => None,
}
}
pub fn into_owned(self) -> Result<ParseTree<C>, Self> {
match self {
Self::Contains(tree) => Ok(tree),
other => Err(other),
}
}
}