mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Replace the Str implementation for AttrValue by a Deref implementation.
This commit is contained in:
parent
4108af0c11
commit
41cc0a939e
16 changed files with 43 additions and 41 deletions
|
@ -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]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue