Stream: project-error-handling

Topic: Global Hooks


view this post on Zulip Sean Chen (he/him) (Oct 02 2020 at 14:32):

Is there a good explanation of what global hooks are and how they're used to implement error handling behavior?

view this post on Zulip Charles Ellis O'Riley Jr. (Oct 02 2020 at 15:39):

That would be nice to know

view this post on Zulip Jane Lusby (Oct 02 2020 at 21:02):

I think the closest thing might be the description of how #[panic_handler] works, or possibly the extern existential types RFC

view this post on Zulip Jane Lusby (Oct 02 2020 at 21:02):

let me link those rq

view this post on Zulip Jane Lusby (Oct 02 2020 at 21:03):

https://rustc-dev-guide.rust-lang.org/panic-implementation.html?highlight=panic_handler#panicking-in-rust

view this post on Zulip Jane Lusby (Oct 02 2020 at 21:03):

https://github.com/Ericson2314/rust-rfcs/blob/extern-existential-type/text/0000-extern-existential-type.md

view this post on Zulip Jane Lusby (Oct 02 2020 at 21:03):

to my knowledge though hooks aren't really a formal concept in rust

view this post on Zulip Jane Lusby (Oct 02 2020 at 21:03):

they're mostly a hack

view this post on Zulip Jane Lusby (Oct 02 2020 at 21:04):

and when ppl talk about hooks there are different kinds

view this post on Zulip Jane Lusby (Oct 02 2020 at 21:04):

like theres #[panic_handler] which is a language item hook

view this post on Zulip Jane Lusby (Oct 02 2020 at 21:04):

and as far as I know its essentially just an extern function where the compiler handles making sure the definitions resolve to the right symbols via the attribute

view this post on Zulip Jane Lusby (Oct 02 2020 at 21:05):

but you're essentially just declaring a function in one compilation unit then defining it in another

view this post on Zulip Jane Lusby (Oct 02 2020 at 21:05):

and if two crates define that same symbol then you cant link them together

view this post on Zulip Jane Lusby (Oct 02 2020 at 21:05):

then theres the hook from std::panic::set_hook

view this post on Zulip Jane Lusby (Oct 02 2020 at 21:06):

which is different, because unlike the #[panic_handler], which is static, this can be set at runtime

view this post on Zulip Jane Lusby (Oct 02 2020 at 21:06):

and it is ultimately built ontop of #[panic_handler]

view this post on Zulip Jane Lusby (Oct 02 2020 at 21:06):

and this is how the standard library lets applications customize panic behaviour while still having default panic handler behaviour

view this post on Zulip Lokathor (Oct 03 2020 at 00:01):

alloc_error_handler is another global hook


Last updated: Jan 29 2022 at 10:29 UTC