use std::cmp::Ordering;
use std::ops::Deref;
use std::sync::Arc;
#[derive(Debug)]
pub enum Sod<T: ?Sized + 'static> {
Static(&'static T),
Dynamic(Arc<T>),
}
impl<T: ?Sized> Deref for Sod<T> {
type Target = T;
fn deref(&self) -> &T {
match *self {
Sod::Static(t) => t,
Sod::Dynamic(ref t) => t,
}
}
}
impl<T: ?Sized> Clone for Sod<T> {
fn clone(&self) -> Self {
match *self {
Sod::Static(t) => Sod::Static(t),
Sod::Dynamic(ref t) => Sod::Dynamic(Arc::clone(t)),
}
}
}
impl<T: PartialEq + ?Sized> PartialEq<Sod<T>> for Sod<T> {
fn eq(&self, other: &Self) -> bool {
self.deref().eq(other.deref())
}
}
impl<T: PartialOrd + ?Sized> PartialOrd<Sod<T>> for Sod<T> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.deref().partial_cmp(other.deref())
}
}