Add IntoPropValue implementation to convert from Cows to AttrValue (#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
This commit is contained in:
Tim Kurdov 2023-08-21 17:31:29 +01:00 committed by GitHub
parent afde963230
commit 3c4ac56980
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 0 deletions

View File

@ -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>>>
@ -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>>>
@ -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>>>

View File

@ -1,3 +1,4 @@
use std::borrow::Cow;
use std::rc::Rc;
use implicit_clone::unsync::{IArray, IMap};
@ -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> {
@ -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]