format!
boilerplate reduction for interpolated values
#146
Closed
kirillsemyonkin
started this conversation in
Ideas
Replies: 1 comment 3 replies
-
We can only pick one between The primary reason being that Rust actually explained this with their own See: https://doc.rust-lang.org/edition-guide/rust-2021/panic-macro-consistency.html However, for this specific case, you can write it as: let style = use_style! {
width: ${width}px;
}; |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
As an obvious use-case, whenever CSS units are involved, you have to concatenate a value and a unit:
The alternative part of the code above is more interesting, because it is what this discussion is about: what if the formatting was a part of the stylist (inline) syntax? Here is an example of the idea:
The reason this would work is because all CSS that stylist takes in seems to be a bunch of concatenated strings. This is the reason why writing
${"..."}
appears to work in 100% of all places (not sure about closing blocks using interpolation,... { ... ${"}"}
).unexpected token
.Would there be any performance penalties for usingActually, I think writing a single value should be parsed as if that value was passed in directly, because otherwise something simple likeformat!
always? Maybe an optimization for single values is necessary (although, I heardformat!
already has a short-circuit for single argument)?${width_in_px}
from the first example would break.Beta Was this translation helpful? Give feedback.
All reactions