mcarton / rust-derivative

A set of alternative `derive` attributes for Rust
Apache License 2.0
420 stars 46 forks source link

#[derivative(Debug(value = "..."))] #104

Open kangalio opened 2 years ago

kangalio commented 2 years ago

It would be great to have the option to format a struct field or enum variant as a hardcoded string. For example:

#[derive(Derivative)]
#[derivative(Debug)]
struct Foo {
    #[derivative(Debug(value = "Box<dyn Any>"))]
    data: Box<dyn Any>,
}

// Foo { data: Box<dyn Any> }
println!("{:?}", foo);
KisaragiEffective commented 1 year ago

another example:

#[derive(Derivative)]
#[derivative(Debug)]
pub enum EffectDescriptor<'cls> {
    Output(#[derivative(Debug(value = "closure[thunk]"))] Box<dyn (Fn() -> TypeBox) + 'cls>),
    UpdateVariable {
        ident: String,
        #[derivative(Debug(value = "closure[thunk]"))]
        value: Box<dyn (Fn() -> TypeBox) + 'cls>,
    },
    PushScope,
    PopScope,
}