futursolo / stylist-rs

A CSS-in-Rust styling solution for WebAssembly Applications
https://crates.io/crates/stylist
MIT License
366 stars 22 forks source link

Display of non-owned value is broken #66

Closed futursolo closed 2 years ago

futursolo commented 2 years ago
use stylist::style;

struct MyColors {
    default: String,
}

fn main() {
    let colors = MyColors {
        default: "white".to_string(),
    };
    let colors = &colors;

    format!("color: {color};", color = colors.default); // success
    style!(r#"color: ${color};"#, color = colors.default); // fail
}
error[E0507]: cannot move out of `colours.default` which is behind a shared reference
  --> src/main.rs:14:43
   |
14 |     style!(r#"color: ${color};"#, color = colors.default); // fail
   |                                           ^^^^^^^^^^^^^^ move occurs because `colors.default` has type `String`, which does not implement the `Copy` trait