error-stack: how is Context stored?
#1343
Answered
by
TimDiekmann
Abhicodes-crypto
asked this question in
Help (Libraries)
-
|
In the current_context function I see that C: `static lifetime. Does that mean C is stored for the entire runtime of the process. PS: I'm new to rust |
Beta Was this translation helpful? Give feedback.
Answered by
TimDiekmann
Nov 4, 2022
Replies: 1 comment
-
|
Hi @Abhicodes-crypto and thanks for the question!
A little bit of context;
I hope this can answer your question 🙂 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
vilkinsons
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @Abhicodes-crypto and thanks for the question!
Cinternally is stored asBox<dyn Any>inside ofReport. This means thatCis stored on the heap and will be deallocated as soon asReportgoes out of scope.A little bit of context;
Crequires'staticbecause of two reasons:Cwouldn't be'static, the lifetime would bubble up toReport, so it would become something likeReport<'a, C>. AsReporttypically is used as a return value from a function, dealing with lifetimes is hard, the main issue, however, is thatCis not known anymore at compile time. To allow downcastingC, it's required, thatCis'staticasAnyis implemented for anyTwhereT: 'static. If I remembe…