Replace the Str implementation for AttrValue by a Deref implementation.

This commit is contained in:
Ms2ger 2015-04-25 15:24:27 +02:00
parent 4108af0c11
commit 41cc0a939e
16 changed files with 43 additions and 41 deletions

View file

@ -23,6 +23,7 @@ use string_cache::{Atom, Namespace};
use std::borrow::ToOwned;
use std::cell::Ref;
use std::mem;
use std::ops::Deref;
pub enum AttrSettingType {
FirstSetAttr,
@ -79,8 +80,10 @@ impl AttrValue {
}
}
impl Str for AttrValue {
fn as_slice<'a>(&'a self) -> &'a str {
impl Deref for AttrValue {
type Target = str;
fn deref<'a>(&'a self) -> &'a str {
match *self {
AttrValue::String(ref value) |
AttrValue::TokenList(ref value, _) |
@ -151,7 +154,7 @@ impl<'a> AttrMethods for JSRef<'a, Attr> {
// https://dom.spec.whatwg.org/#dom-attr-value
fn Value(self) -> DOMString {
self.value().as_slice().to_owned()
(**self.value()).to_owned()
}
// https://dom.spec.whatwg.org/#dom-attr-value
@ -299,7 +302,7 @@ impl AttrHelpersForLayout for Attr {
unsafe fn value_ref_forever(&self) -> &'static str {
// This transmute is used to cheat the lifetime restriction.
let value = mem::transmute::<&AttrValue, &AttrValue>(self.value.borrow_for_layout());
value.as_slice()
&**value
}
#[inline]