use crate::dag::Dag;
use std::sync::Arc;
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
pub struct NoDisconnect;
pub trait Disconnectable<L> {
fn disconnect_dag_arc(self, other: Arc<L>) -> Dag<Arc<L>>;
fn disconnect_dag_ref<'s>(&'s self, other: &'s L) -> Dag<&'s L>;
}
impl<L> Disconnectable<L> for NoDisconnect {
fn disconnect_dag_arc(self, other: Arc<L>) -> Dag<Arc<L>> {
Dag::Unary(other)
}
fn disconnect_dag_ref<'s>(&'s self, other: &'s L) -> Dag<&'s L> {
Dag::Unary(other)
}
}
impl<L> Disconnectable<L> for Arc<L> {
fn disconnect_dag_arc(self, other: Arc<L>) -> Dag<Arc<L>> {
Dag::Binary(other, self)
}
fn disconnect_dag_ref<'s>(&'s self, other: &'s L) -> Dag<&'s L> {
Dag::Binary(other, self)
}
}
impl<L> Disconnectable<L> for Option<Arc<L>> {
fn disconnect_dag_arc(self, other: Arc<L>) -> Dag<Arc<L>> {
match self {
Some(right) => Dag::Binary(other, right),
None => Dag::Unary(other),
}
}
fn disconnect_dag_ref<'s>(&'s self, other: &'s L) -> Dag<&'s L> {
match self {
Some(right) => Dag::Binary(other, right),
None => Dag::Unary(other),
}
}
}
impl<L> Disconnectable<L> for Arc<str> {
fn disconnect_dag_arc(self, other: Arc<L>) -> Dag<Arc<L>> {
Dag::Unary(other)
}
fn disconnect_dag_ref<'s>(&'s self, other: &'s L) -> Dag<&'s L> {
Dag::Unary(other)
}
}