-
Notifications
You must be signed in to change notification settings - Fork 153
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
Thoughts on improving style! macro. #268
Comments
Looks good! |
Love it |
Closing since this is now solved. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi.
I have been experimenting on ways to let
style!
macro accept more types that can be some how converted toCSSValue
.Here is how I want to use
style!
macro (from #261 (comment)):Here is a model Flex:
and when I want to view this in the
view
function, I write this in today seed:what I really would like to write is:
So the code would be simple to write and read if
style!
macro support this kind of sugar.The way macro
style!
work is to accept any type that implementInto<CSSValue>
.The problem is that Rust today only accept one blanket implementation, and since there is a blanket implementation
Impl<T: ToString> From<T> for CSSValue
, we cannot add another blanket implementation such as:This blanket impl would allow
style!
macro to accept values such asSome("2px")
andSome(FlexDirection::Row)
..But as you can see this is not supported in Rust today (without specialization at less).
So I went a head and experimenting with specialization (rust-lang/rfcs#1210), but I give up because it's not ready, even if it's ready I don't think that we need to use nightly features in seed.
After that I was thinking to experimenting on the type system and macro to achieve this feature.
after a few searches I found this cool trick/workaround/idea (or what ever they call it) to do the job for us. and I have tried it and it worked!.
So let say we want
style!
to support every type that implToString
as seed already do, and support anyOption<T> where T: ToString
this last one is the new thing we want to add tostyle!
macro.Here is a full example doing that:
This workaround have some limitation which I don't think they are very important in our case.
I wrote this long issue to know if this solution is valid and would be accepted if I make PR for it. Also I would love to know if you guys have better ideas.
Thanks for reading.
The text was updated successfully, but these errors were encountered: