aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/spanned.rs37
1 files changed, 36 insertions, 1 deletions
diff --git a/src/spanned.rs b/src/spanned.rs
index e3c2774..9ee56ae 100644
--- a/src/spanned.rs
+++ b/src/spanned.rs
@@ -1,5 +1,8 @@
use serde::{de, ser};
+use std::borrow::Borrow;
+use std::cmp::Ordering;
use std::fmt;
+use std::hash::{Hash, Hasher};
pub(crate) const NAME: &str = "$__toml_private_Spanned";
pub(crate) const START: &str = "$__toml_private_start";
@@ -28,7 +31,7 @@ pub(crate) const VALUE: &str = "$__toml_private_value";
/// assert_eq!(u.s.into_inner(), String::from("value"));
/// }
/// ```
-#[derive(Clone, Debug, PartialEq, Eq, Hash)]
+#[derive(Clone, Debug)]
pub struct Spanned<T> {
/// The start range.
start: usize,
@@ -70,6 +73,38 @@ impl<T> Spanned<T> {
}
}
+impl Borrow<str> for Spanned<String> {
+ fn borrow(&self) -> &str {
+ &self.get_ref()
+ }
+}
+
+impl<T: PartialEq> PartialEq for Spanned<T> {
+ fn eq(&self, other: &Self) -> bool {
+ self.value.eq(&other.value)
+ }
+}
+
+impl<T: Eq> Eq for Spanned<T> {}
+
+impl<T: Hash> Hash for Spanned<T> {
+ fn hash<H: Hasher>(&self, state: &mut H) {
+ self.value.hash(state);
+ }
+}
+
+impl<T: PartialOrd> PartialOrd for Spanned<T> {
+ fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
+ self.value.partial_cmp(&other.value)
+ }
+}
+
+impl<T: Ord> Ord for Spanned<T> {
+ fn cmp(&self, other: &Self) -> Ordering {
+ self.value.cmp(&other.value)
+ }
+}
+
impl<'de, T> de::Deserialize<'de> for Spanned<T>
where
T: de::Deserialize<'de>,