1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
use std::hash::Hash; use std::fmt; #[cfg(not(debug_assertions))] pub trait Label = Hash + Clone + Eq; #[cfg(debug_assertions)] pub trait Label = Hash + Clone + Eq + fmt::Display + fmt::Debug; // impl Label for () {} // impl Label for String {} // impl<'a> Label for &'a str {} // impl Label for char {} // impl Label for bool {} // impl Label for u8 {} // impl Label for u16 {} // impl Label for u32 {} // impl Label for u64 {} // impl Label for i8 {} // impl Label for i16 {} // impl Label for i32 {} // impl Label for i64 {} pub type Labeled<T, L> = (T, L); #[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] pub struct NoLabel; impl fmt::Display for NoLabel { fn fmt(&self, _f: &mut fmt::Formatter) -> fmt::Result { Ok(()) } } // impl<T, L: Label> Labeled<T, L> { // pub fn new(t: T, label: L) -> Labeled<T, L> { // Labeled { // t: t, // label: label // } // } // } // // impl<T: Clone, L: Label> Clone for Labeled<T, L> { // fn clone(&self) -> Self { // Labeled { // t: self.t.clone(), // label: self.label.clone() // } // } // } // // impl<T: Hash, L: Label> Hash for Labeled<T, L> { // fn hash<H: Hasher>(&self, state: &mut H) { // self.t.hash(state); // self.label.hash(state); // } // } // // impl<T: PartialEq, L: Label> PartialEq for Labeled<T, L> { // fn eq(&self, other: &Labeled<T, L>) -> bool { // self.label == other.label && self.t == other.t // } // } // // impl<T: Eq, L: Label> Eq for Labeled<T, L> { }