rust-lang / rust-lang/rust

type_info: reflection on non-dyn compatible traits

Open
#156,286 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-enhancement F-type_info
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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: https://github.com/rust-lang/rust/issues/146922 and https://github.com/rust-lang/rust/issues/144361

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file, test, or entry point is named. Start by reading the issue and the related issues #146922 and #144361, then clarify the design for trait_of! and associated-item metadata with the maintainers. Done means an agreed reflection design is implemented and its behavior is covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.