diff --git a/src/dom.rs b/src/dom.rs index 7adf1db..c8c0ef1 100644 --- a/src/dom.rs +++ b/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 = 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()))) diff --git a/src/traits.rs b/src/traits.rs index ebc3a8a..af184a7 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -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 AsStr for Box 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 {