use std::cmp::{Ordering, PartialOrd}; use smol_str::SmolStr; use crate::legacy::{ElementId, Key, OpId}; impl PartialOrd for Key { fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } impl Ord for Key { fn cmp(&self, other: &Self) -> Ordering { match (self, other) { (Key::Map(a), Key::Map(b)) => a.cmp(b), (Key::Seq(a), Key::Seq(b)) => a.cmp(b), (Key::Map(_), _) => Ordering::Less, (_, Key::Map(_)) => Ordering::Greater, } } } impl From for Key { fn from(id: OpId) -> Self { Key::Seq(ElementId::Id(id)) } } impl From<&OpId> for Key { fn from(id: &OpId) -> Self { Key::Seq(ElementId::Id(id.clone())) } } impl From for Key { fn from(id: ElementId) -> Self { Key::Seq(id) } } impl From for Key where S: AsRef, { fn from(s: S) -> Self { Key::Map(SmolStr::new(s)) } }