Skip to content

error-stack: how is Context stored? #1343

Discussion options

You must be logged in to vote

Hi @Abhicodes-crypto and thanks for the question!

C internally is stored as Box<dyn Any> inside of Report. This means that C is stored on the heap and will be deallocated as soon as Report goes out of scope.

A little bit of context; C requires 'static because of two reasons:

  • If C wouldn't be 'static, the lifetime would bubble up to Report, so it would become something like Report<'a, C>. As Report typically is used as a return value from a function, dealing with lifetimes is hard, the main issue, however, is that
  • the exact type of C is not known anymore at compile time. To allow downcasting C, it's required, that C is 'static as Any is implemented for any T where T: 'static. If I remembe…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by vilkinsons
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) area/libs Relates to first-party libraries/crates/packages (area)
2 participants