Skip to content

error-stack expose Frame::type_id #1289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 30, 2022
Merged

error-stack expose Frame::type_id #1289

merged 2 commits into from
Oct 30, 2022

Conversation

indietyp
Copy link
Member

@indietyp indietyp commented Oct 29, 2022

🌟 What is the purpose of this PR?

While developing deer (which heavily uses error-stack and Frames for errors), I often tried to get the current type contained in a Frame, before #1288 error-stack had a pub(crate) function with the same name (type_id). Even though error-stack no longer directly uses TypeId, I think it is still valuable to add the method for lower-level use cases outside of error-stack, to inspect the contained type easily.

This is entirely optional, one can also repeatedly call Frame::is<T>() for every expected type, but this isn't ideal, as it isn't very straightforward, nor ergonomic, or as performant as a simple lookup in a HashSet (or similar).

🔍 What does this change?

  • exposes Frame::type_id

📜 Does this require a change to the docs?

Yes, the newly exposed method is documented.

❓ How to test this?

An additional test has been added to verify the behavior.

@indietyp indietyp requested a review from TimDiekmann October 29, 2022 19:57
@github-actions github-actions bot added the area/libs > error-stack Affects the `error-stack` crate (library) label Oct 29, 2022
@codecov
Copy link

codecov bot commented Oct 29, 2022

Codecov Report

❗ No coverage uploaded for pull request base (main@5e05fa4). Click here to learn what that means.
The diff coverage is n/a.

@@          Coverage Diff           @@
##             main   #1289   +/-   ##
======================================
  Coverage        ?   1.33%           
======================================
  Files           ?     246           
  Lines           ?    6984           
  Branches        ?     896           
======================================
  Hits            ?      93           
  Misses          ?    6886           
  Partials        ?       5           
Flag Coverage Δ
backend-integration-tests 2.85% <0.00%> (?)
unit-tests 1.06% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@TimDiekmann TimDiekmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the change. I think this can be really useful for downstream crates, which need more information on the Frames. Thank you!

@indietyp indietyp merged commit b676ae7 into main Oct 30, 2022
@indietyp indietyp deleted the bm/error-stack/type-id branch October 30, 2022 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/libs > error-stack Affects the `error-stack` crate (library)
Development

Successfully merging this pull request may close these issues.

2 participants