futursolo/stylist-rs

Display of non-owned value is broken

Closed this issue · 0 comments

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