aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/str.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom/bindings/str.rs')
-rw-r--r--components/script/dom/bindings/str.rs56
1 files changed, 55 insertions, 1 deletions
diff --git a/components/script/dom/bindings/str.rs b/components/script/dom/bindings/str.rs
index 28a429f846c..3142f011c9b 100644
--- a/components/script/dom/bindings/str.rs
+++ b/components/script/dom/bindings/str.rs
@@ -79,9 +79,63 @@ impl ops::Deref for ByteString {
/// A string that is constructed from a UCS-2 buffer by replacing invalid code
/// points with the replacement character.
-#[derive(Clone, Default, MallocSizeOf)]
+#[derive(Clone, Default, Eq, MallocSizeOf, Ord, PartialEq, PartialOrd)]
pub struct USVString(pub String);
+impl Borrow<str> for USVString {
+ #[inline]
+ fn borrow(&self) -> &str {
+ &self.0
+ }
+}
+
+impl Deref for USVString {
+ type Target = str;
+
+ #[inline]
+ fn deref(&self) -> &str {
+ &self.0
+ }
+}
+
+impl DerefMut for USVString {
+ #[inline]
+ fn deref_mut(&mut self) -> &mut str {
+ &mut self.0
+ }
+}
+
+impl AsRef<str> for USVString {
+ fn as_ref(&self) -> &str {
+ &self.0
+ }
+}
+
+impl fmt::Display for USVString {
+ #[inline]
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ fmt::Display::fmt(&**self, f)
+ }
+}
+
+impl PartialEq<str> for USVString {
+ fn eq(&self, other: &str) -> bool {
+ &**self == other
+ }
+}
+
+impl<'a> PartialEq<&'a str> for USVString {
+ fn eq(&self, other: &&'a str) -> bool {
+ &**self == *other
+ }
+}
+
+impl From<String> for USVString {
+ fn from(contents: String) -> USVString {
+ USVString(contents)
+ }
+}
+
/// Returns whether `s` is a `token`, as defined by
/// [RFC 2616](http://tools.ietf.org/html/rfc2616#page-17).
pub fn is_token(s: &[u8]) -> bool {