From d19558f0afe0162ca289949ebe3694d9bc609ac4 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Fri, 22 Jul 2016 03:41:24 +0200 Subject: [PATCH 1/2] Implement Default and PartialEq. --- Cargo.toml | 2 +- src/atom/mod.rs | 6 ++++++ src/namespace.rs | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 57c8cf8..0ddc506 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "string_cache" -version = "0.2.21" +version = "0.2.22" authors = [ "The Servo Project Developers" ] description = "A string interning library for Rust, developed as part of the Servo project." license = "MIT / Apache-2.0" diff --git a/src/atom/mod.rs b/src/atom/mod.rs index 89beb4e..fd0a58e 100644 --- a/src/atom/mod.rs +++ b/src/atom/mod.rs @@ -215,6 +215,12 @@ impl PartialEq for str { } } +impl PartialEq for Atom { + fn eq(&self, other: &String) -> bool { + &self[..] == &other[..] + } +} + impl<'a> From> for Atom { #[inline] fn from(string_to_add: Cow<'a, str>) -> Atom { diff --git a/src/namespace.rs b/src/namespace.rs index cae98dd..fe2cbae 100644 --- a/src/namespace.rs +++ b/src/namespace.rs @@ -19,6 +19,12 @@ use std::ops; #[cfg_attr(feature = "heap_size", derive(HeapSizeOf))] pub struct Namespace(pub Atom); +impl Default for Namespace { + fn default() -> Self { + ns!() + } +} + pub struct BorrowedNamespace<'a>(pub &'a Namespace); impl<'a> ops::Deref for BorrowedNamespace<'a> { From 91314e0e656e2eb4ea5c2b8526dafb148c47e2dc Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Fri, 22 Jul 2016 16:08:26 +0200 Subject: [PATCH 2/2] Implement Default for Atom --- src/atom/mod.rs | 6 ++++++ src/namespace.rs | 8 +------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/atom/mod.rs b/src/atom/mod.rs index fd0a58e..4878320 100644 --- a/src/atom/mod.rs +++ b/src/atom/mod.rs @@ -203,6 +203,12 @@ impl Atom { } } +impl Default for Atom { + fn default() -> Self { + atom!("") + } +} + impl PartialEq for Atom { fn eq(&self, other: &str) -> bool { &self[..] == other diff --git a/src/namespace.rs b/src/namespace.rs index fe2cbae..9ae836b 100644 --- a/src/namespace.rs +++ b/src/namespace.rs @@ -15,16 +15,10 @@ use std::ops; /// An atom that is meant to represent a namespace in the HTML / XML sense. /// Whether a given string represents a namespace is contextual, so this is /// a transparent wrapper that will not catch all mistakes. -#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone)] +#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Default)] #[cfg_attr(feature = "heap_size", derive(HeapSizeOf))] pub struct Namespace(pub Atom); -impl Default for Namespace { - fn default() -> Self { - ns!() - } -} - pub struct BorrowedNamespace<'a>(pub &'a Namespace); impl<'a> ops::Deref for BorrowedNamespace<'a> {