Skip to content

Substitution/concatenation of token names #52

@oeed

Description

@oeed

Short Description:

I was hoping to have a way to substitute a value in to the name of a token. For example:

#[duplicate_item(
  int_type  max_value;
  [ u8 ]    [ 255 ];
  [ u16 ]   [ 65_535 ];
  [ u32 ]   [ 4_294_967_295 ];
)]
fn is_[int_type]_max(&self) -> bool {
  *self == max_value
}

// Generates...
fn is_u8_max(&self) -> bool {
  *self == 255
}

fn is_u16_max(&self) -> bool {
  *self == 65_535
}
// etc.

I've read through the docs and can't seem to find a way to do so without restoring to using something like paste!. Is that possible?

Metadata

Metadata

Assignees

No one assigned

    Labels

    D-discussionA decision (D) has not been made yet and is open to discussionI-featureThis issue (I) regards a (potential) feature in the projectT-acceptedTriage (T): Initial review accepted issue/PR as valid

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions