use core::fmt;
use super::*;
#[derive(Copy, Clone, PartialEq, Eq)]
pub enum RegionBranchPoint {
Parent,
Child(RegionRef),
}
impl fmt::Display for RegionBranchPoint {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Parent => f.write_str("parent"),
Self::Child(region) => {
write!(f, "child({})", region.borrow().region_number())
}
}
}
}
impl fmt::Debug for RegionBranchPoint {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Parent => f.write_str("Parent"),
Self::Child(region) => {
f.debug_tuple("Child").field(&format_args!("{region:p}")).finish()
}
}
}
}
impl RegionBranchPoint {
#[inline]
pub fn is_parent(&self) -> bool {
matches!(self, Self::Parent)
}
pub fn region(&self) -> Option<RegionRef> {
match self {
Self::Child(region) => Some(*region),
Self::Parent => None,
}
}
}
impl<'a> From<RegionSuccessor<'a>> for RegionBranchPoint {
fn from(succ: RegionSuccessor<'a>) -> Self {
match succ.into_successor() {
None => Self::Parent,
Some(succ) => Self::Child(succ),
}
}
}