Making AsStr more generic (accepting & and &mut)
This commit is contained in:
parent
3887738f9b
commit
84c38d02a7
13
src/dom.rs
13
src/dom.rs
|
@ -1076,11 +1076,24 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn style_signal_types() {
|
||||
lazy_static! {
|
||||
static ref FOO: String = "foo".to_owned();
|
||||
}
|
||||
|
||||
let _a: DomBuilder<HtmlElement> = DomBuilder::new(create_element_ns("div", HTML_NAMESPACE))
|
||||
.style_signal("foo", always("bar"))
|
||||
.style_signal("foo", always("bar".to_owned()))
|
||||
.style_signal("foo", always("bar".to_owned()).map(|x| RefFn::new(x, |x| x.as_str())))
|
||||
|
||||
.style("foo".to_owned(), "bar".to_owned())
|
||||
.style_signal("foo".to_owned(), always("bar".to_owned()))
|
||||
|
||||
.style(&"foo".to_owned(), &"bar".to_owned())
|
||||
.style(Box::new("foo".to_owned()), Box::new("bar".to_owned()))
|
||||
|
||||
.style_signal(&*FOO, always(&*FOO))
|
||||
.style_signal(Box::new("foo".to_owned()), always(Box::new("bar".to_owned())))
|
||||
|
||||
//.style_signal(vec!["-moz-foo", "-webkit-foo", "foo"].as_slice(), always("bar"))
|
||||
//.style_signal(vec!["-moz-foo", "-webkit-foo", "foo"].as_slice(), always("bar".to_owned()))
|
||||
//.style_signal(vec!["-moz-foo", "-webkit-foo", "foo"].as_slice(), always("bar".to_owned()).map(|x| RefFn::new(x, |x| x.as_str())))
|
||||
|
|
|
@ -21,6 +21,27 @@ pub trait AsStr {
|
|||
fn as_str(&self) -> &str;
|
||||
}
|
||||
|
||||
impl<'a, A> AsStr for &'a A where A: AsStr {
|
||||
#[inline]
|
||||
fn as_str(&self) -> &str {
|
||||
AsStr::as_str(*self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, A> AsStr for &'a mut A where A: AsStr {
|
||||
#[inline]
|
||||
fn as_str(&self) -> &str {
|
||||
AsStr::as_str(*self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<A> AsStr for Box<A> where A: AsStr {
|
||||
#[inline]
|
||||
fn as_str(&self) -> &str {
|
||||
AsStr::as_str(&**self)
|
||||
}
|
||||
}
|
||||
|
||||
impl AsStr for String {
|
||||
#[inline]
|
||||
fn as_str(&self) -> &str {
|
||||
|
@ -28,6 +49,13 @@ impl AsStr for String {
|
|||
}
|
||||
}
|
||||
|
||||
impl AsStr for str {
|
||||
#[inline]
|
||||
fn as_str(&self) -> &str {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> AsStr for &'a str {
|
||||
#[inline]
|
||||
fn as_str(&self) -> &str {
|
||||
|
|
Loading…
Reference in New Issue