Jonathan ‘theJPster’ Pallant on Nostr: Idle thought: what if in Rust you were able to write: pub nopanic fn foo() { … } ...
Idle thought: what if in Rust you were able to write:
pub nopanic fn foo() { … }
Functions marked nopanic can only perform operations that are themselves nopanic. A bit like const fns. If you really wanted you could make main a nopanic function. Unchecked arithmetic and slicing, and functions like unwrap, would all be forbidden inside a nopanic function.
You could also use the keyword “safe” instead of “nopanic”, leaving the default to be ?safe, or semi-safe (no UB, but could panic).
pub nopanic fn foo() { … }
Functions marked nopanic can only perform operations that are themselves nopanic. A bit like const fns. If you really wanted you could make main a nopanic function. Unchecked arithmetic and slicing, and functions like unwrap, would all be forbidden inside a nopanic function.
You could also use the keyword “safe” instead of “nopanic”, leaving the default to be ?safe, or semi-safe (no UB, but could panic).