Skip to content

type_info: reflection on non-dyn compatible traits #156286

@khionu

Description

@khionu

Right now, if a trait as associated items, reflection is difficult to impossible. My personal case is trying to reflect on an async function. I quickly run into the problem of being unable to determine if a function returns a Future because I have no way of binding Future::Output.

A possible solution that @oli-obk and I brainstormed would be a trait_of! macro, which would take the implementer, plus the trait as an ident, and return a Trait. Further, extensions similar to the below would need to be added around Trait.

pub struct Trait {
  // ...
  pub associated: &'static [TraitAssocProperty];
}

pub struct TraitAssocProperty {
  pub name: &'static str;
  pub kind: TraitAssocPropertyKind;
  pub ty: TypeId,
}

pub enum TraitAssocPropertyKind {
  Constant,
  Type
}

Related to: #146922 and #144361

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.F-type_info#![feature(type_info)]

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions