#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum AdoptAs {
FirstChild,
LastChild,
PreviousSibling,
NextSibling,
}
impl AdoptAs {
#[must_use]
pub(super) fn insert_with_anchor<Id>(self, anchor: Id) -> InsertAs<Id> {
match self {
Self::FirstChild => InsertAs::FirstChildOf(anchor),
Self::LastChild => InsertAs::LastChildOf(anchor),
Self::PreviousSibling => InsertAs::PreviousSiblingOf(anchor),
Self::NextSibling => InsertAs::NextSiblingOf(anchor),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[allow(clippy::enum_variant_names)]
pub enum InsertAs<Id> {
FirstChildOf(Id),
LastChildOf(Id),
PreviousSiblingOf(Id),
NextSiblingOf(Id),
}
impl<Id> InsertAs<Id> {
pub(super) fn map<U, F>(self, f: F) -> InsertAs<U>
where
F: FnOnce(Id) -> U,
{
match self {
Self::FirstChildOf(id) => InsertAs::FirstChildOf(f(id)),
Self::LastChildOf(id) => InsertAs::LastChildOf(f(id)),
Self::PreviousSiblingOf(id) => InsertAs::PreviousSiblingOf(f(id)),
Self::NextSiblingOf(id) => InsertAs::NextSiblingOf(f(id)),
}
}
pub(super) fn to_anchor(self) -> Id
where
Id: Copy,
{
match self {
Self::FirstChildOf(id) => id,
Self::LastChildOf(id) => id,
Self::PreviousSiblingOf(id) => id,
Self::NextSiblingOf(id) => id,
}
}
}