Skip to content

Commit

Permalink
Add IntoPropValue implementation to convert from Cows to `AttrVal…
Browse files Browse the repository at this point in the history
…ue` (#3346)

* added IntoPropValue impls to & from Cows

* fixed formatting & test's expected output

* fixed formatting

* fixed macro test's expected output

* removed conversion to String & Rc

* fixed macro tests

* fixed macro tests
  • Loading branch information
its-the-shrimp authored Aug 21, 2023
1 parent afde963 commit 3c4ac56
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/yew-macro/tests/html_macro/element-fail.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ error[E0277]: the trait bound `Option<NotToString>: IntoPropValue<Option<implici
= help: the following other types implement trait `IntoPropValue<T>`:
<Option<&'static str> as IntoPropValue<Option<String>>>
<Option<&'static str> as IntoPropValue<Option<implicit_clone::unsync::IString>>>
<Option<Cow<'static, str>> as IntoPropValue<Option<implicit_clone::unsync::IString>>>
<Option<F> as IntoPropValue<Option<yew::Callback<I, O>>>>
<Option<Rc<str>> as IntoPropValue<Option<implicit_clone::unsync::IString>>>
<Option<String> as IntoPropValue<Option<implicit_clone::unsync::IString>>>
Expand All @@ -519,6 +520,7 @@ error[E0277]: the trait bound `Option<{integer}>: IntoPropValue<Option<implicit_
= help: the following other types implement trait `IntoPropValue<T>`:
<Option<&'static str> as IntoPropValue<Option<String>>>
<Option<&'static str> as IntoPropValue<Option<implicit_clone::unsync::IString>>>
<Option<Cow<'static, str>> as IntoPropValue<Option<implicit_clone::unsync::IString>>>
<Option<F> as IntoPropValue<Option<yew::Callback<I, O>>>>
<Option<Rc<str>> as IntoPropValue<Option<implicit_clone::unsync::IString>>>
<Option<String> as IntoPropValue<Option<implicit_clone::unsync::IString>>>
Expand Down Expand Up @@ -632,6 +634,7 @@ error[E0277]: the trait bound `Option<yew::NodeRef>: IntoPropValue<yew::NodeRef>
= help: the following other types implement trait `IntoPropValue<T>`:
<Option<&'static str> as IntoPropValue<Option<String>>>
<Option<&'static str> as IntoPropValue<Option<implicit_clone::unsync::IString>>>
<Option<Cow<'static, str>> as IntoPropValue<Option<implicit_clone::unsync::IString>>>
<Option<F> as IntoPropValue<Option<yew::Callback<I, O>>>>
<Option<Rc<str>> as IntoPropValue<Option<implicit_clone::unsync::IString>>>
<Option<String> as IntoPropValue<Option<implicit_clone::unsync::IString>>>
Expand Down
3 changes: 3 additions & 0 deletions packages/yew/src/html/conversion/into_prop_value.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::borrow::Cow;
use std::rc::Rc;

use implicit_clone::unsync::{IArray, IMap};
Expand Down Expand Up @@ -186,6 +187,7 @@ impl_into_prop!(|value: &'static str| -> String { value.to_owned() });
impl_into_prop!(|value: &'static str| -> AttrValue { AttrValue::Static(value) });
impl_into_prop!(|value: String| -> AttrValue { AttrValue::Rc(Rc::from(value)) });
impl_into_prop!(|value: Rc<str>| -> AttrValue { AttrValue::Rc(value) });
impl_into_prop!(|value: Cow<'static, str>| -> AttrValue { AttrValue::from(value) });

impl<T: ImplicitClone + 'static> IntoPropValue<IArray<T>> for &'static [T] {
fn into_prop_value(self) -> IArray<T> {
Expand Down Expand Up @@ -226,6 +228,7 @@ mod test {
let _: AttrValue = "foo".into_prop_value();
let _: Option<AttrValue> = "foo".into_prop_value();
let _: Option<AttrValue> = Rc::<str>::from("foo").into_prop_value();
let _: Option<AttrValue> = Cow::Borrowed("foo").into_prop_value();
}

#[test]
Expand Down

0 comments on commit 3c4ac56

Please sign in to comment.