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!
C
internally is stored asBox<dyn Any>
inside ofReport
. This means thatC
is stored on the heap and will be deallocated as soon asReport
goes out of scope.A little bit of context;
C
requires'static
because of two reasons:C
wouldn't be'static
, the lifetime would bubble up toReport
, so it would become something likeReport<'a, C>
. AsReport
typically is used as a return value from a function, dealing with lifetimes is hard, the main issue, however, is thatC
is not known anymore at compile time. To allow downcastingC
, it's required, thatC
is'static
asAny
is implemented for anyT
whereT: 'static
. If I remembe…