Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Default and PartialEq<String>. #165

Merged
merged 2 commits into from
Jul 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
12 changes: 12 additions & 0 deletions src/atom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ impl Atom {
}
}

impl Default for Atom {
fn default() -> Self {
atom!("")
}
}

impl PartialEq<str> for Atom {
fn eq(&self, other: &str) -> bool {
&self[..] == other
Expand All @@ -215,6 +221,12 @@ impl PartialEq<Atom> for str {
}
}

impl PartialEq<String> for Atom {
fn eq(&self, other: &String) -> bool {
&self[..] == &other[..]
}
}

impl<'a> From<Cow<'a, str>> for Atom {
#[inline]
fn from(string_to_add: Cow<'a, str>) -> Atom {
Expand Down
2 changes: 1 addition & 1 deletion src/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ 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);

Expand Down