From 20b131af172ac07ebc817bc24b3601d27a939646 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Tue, 6 Sep 2016 15:31:43 +0200 Subject: [PATCH] Implement Borrow for DOMString Useful to use DOMString as a HashMap key type. --- components/script/dom/bindings/str.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/components/script/dom/bindings/str.rs b/components/script/dom/bindings/str.rs index c73a08d182b7..2e28a1b314e7 100644 --- a/components/script/dom/bindings/str.rs +++ b/components/script/dom/bindings/str.rs @@ -5,7 +5,7 @@ //! The `ByteString` struct. use std::ascii::AsciiExt; -use std::borrow::{ToOwned, Cow}; +use std::borrow::{Borrow, Cow, ToOwned}; use std::fmt; use std::hash::{Hash, Hasher}; use std::ops; @@ -180,6 +180,13 @@ impl DOMString { } } +impl Borrow for DOMString { + #[inline] + fn borrow(&self) -> &str { + &self.0 + } +} + impl Default for DOMString { fn default() -> Self { DOMString(String::new())