You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note that FlexDirection, FlexWrap, JustifyContent and AlignItems all implement Display trait.
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 implement Into<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 as Some("2px") and Some(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 impl ToString as seed already do, and support any Option<T> where T: ToString this last one is the new thing we want to add to style! macro.
This workaround have some limitation which I don't think they are very important in our case.
Note: This improvement can be applied to attrs! macro too.
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:
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: