kvarn_utils

Macro field_str

source
macro_rules! field_str {
    ($self:ident.$field:ident) => { ... };
}
Expand description

Stringify $field on $self. This only returns the field name. This is constructed to make your IDE recognize the input as the actual field. This means renaming is applied to the string returned from this when you rename a field in your IDE.

This is useful for debug implementations.

ยงExamples

use kvarn_utils::field_str;

struct Foo {
    bar: u128,
}
impl Foo {
    fn name(&self) -> &'static str {
        field_str!(self.bar)
    }
}

let foo = Foo { bar: 42 };
assert_eq!(foo.name(), "bar");