-
-
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
Feature request: Add support of optional class names #936
Comments
Agreed that this would be a great feature! I was just talking in the gitter chatroom about Yew's api being more flexible in general... more in line with this: https://deterministic.space/elegant-apis-in-rust.html#intooption_ |
This document is very helpful. |
You read my mind 👍 |
I tried to use Maybe the problem could be solved with specialization, since the input could either be It describes a way to use autoref for specializations within macros only. seed-rs/seed#268 did something very simmilar:
Maybe this method also allows for passing Iterators (or Maybe this method could also be applied to #903, enabling the use of optional |
@LiquidBlock that workaround sounds promising! Is that something you're interested in tackling? |
I was looking into it and i had something that worked to some extend, but I also run into some problems. I am not so sure if specialization (even with the workaround) does the trick for allowing both |
Is your feature request related to a problem? Please describe.
When using multiple class names, i sometimes want to add optional classes (of type
Option<String>
):Describe the solution you'd like
I would love to be able to use
&str
,String
,Option<String>
(and similar) together:This, of course, does not work with
Vec<&str>
, norVec<T>
whereT: AsRef<str>
:yew/src/virtual_dom/mod.rs
Line 128 in 1ede167
But the
html!
macro does not require for a vector of same types and the code even refers to it as tuple:yew/crates/macro/src/html_tree/html_tag/mod.rs
Lines 132 to 133 in c7c9dcd
Describe alternatives you've considered
An alternative, would be to allow for a vector of optional values to be converted into
Classes
.E.g.
All solutions above have the problem, that it might not be possible to detect if an element is of type
Option<T>
or of typeT
whereT: AsRef<str>
in both cases.E.g. consider:
which is not possible, as far as i know, due to E0119:
Another way to archive this feature would be to combine this feature request with #903 and use
class?
withOption<String>
,Option<&str>
andVec<Option<T>>
(instead ofOption<Vec<T>>
whereT: AsRef<str>
) instead ofOption<Classes>
.E.g.
Maybe there is another way to archive a solution to this problem.
E.g. by not using
AsRef<str>
, but rather implement versions forVec<String>
andVec<&str>
, but that would be a breaking change andAsRef<str>
might be more desirable than this proposed feature. (solution 4
)The text was updated successfully, but these errors were encountered: