-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added IntoPropValue
implementation to convert from Cow
s
#3346
added IntoPropValue
implementation to convert from Cow
s
#3346
Conversation
IntoPropValue
implementation to convert from Cow
s
Visit the preview URL for this PR (updated for commit 0cdeca7): https://yew-rs-api--pr3346-add-into-prop-value-wx6r6769.web.app (expires Sun, 27 Aug 2023 22:15:17 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 |
Size Comparison
✅ None of the examples has changed their size significantly. |
Benchmark - SSRYew Master
Pull Request
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from the couple of comments about conversions, this looks good to me. Thanks for the PR!
@@ -182,10 +183,13 @@ macro_rules! impl_into_prop { | |||
} | |||
|
|||
// implemented with literals in mind | |||
impl_into_prop!(|value: &'static str| -> String { value.to_owned() }); | |||
impl_into_prop!(<'a> |value: &'a str| -> String { value.to_owned() }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a fan of this conversion, but since we were already doing it for 'static
, this isn't much worse either
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally it should be done for AttrValue anyway. I guess those are here for backward compatibility more than anything
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_into_prop!(<'a> |value: Cow<'a, str>| -> String { Cow::into_owned(value) }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if Cow is Borrowed? I don't think we should be implicitly cloning it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we already implicitly convert a &str
into String
, implicitly converting a Cow<'a, str>
, which is either a String
or a &'a str
, to String
is just a logical continuation in my opinion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely sure if we should add implementation on something that should be deprecated.
The way I see it, everybody should use AttrValue and not String in their Props.
The fact that things work for String is probably just a backward compatibility thing.
Anybody else has an opinion on this?
Now that I look back at it, I do agree that an |
I agree with this. I think we should emit a deprecation warning if String conversion is used and redirect everyone to use EDIT: apparently we can't deprecate trait
Sounds good. Curious, can we have a blanket implementation for anything that AttrValue can be constructed from? |
I've tested it and it unconditionally reports the implementation itself as calling to deprecated code, seems like it doesn't work |
Oh, that's too bad then. I was hoping the macro call would make it not do that... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Can you please fix the conflicts so this can be merged?
I wonder if we can emit such a warning from the derive macro of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm already approving the change so the PR won't stale. But I do think it would be useful to add a warning for the users to discourage the use of String instead of AttrValue.
I've just added such a warning in #3382 |
Description
IntoPropValue
to allow for conversion fromCow
simpl IntoPropValue<String> for &'static str
intoimpl<'a> IntoPropValue<String> for &'a str
, making it more genericChecklist