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).
Published at
2024-02-17 16:29:47Event JSON
{
"id": "19f68f65d2d2d0fc8acf027bcfacdac377fbc085599f352ffcca671ddc0cdaaf",
"pubkey": "d54a90e999f965d240a0a358300b95d7182adbdec1f8095d092fca7c9eefe296",
"created_at": 1708187387,
"kind": 1,
"tags": [
[
"proxy",
"https://hachyderm.io/users/thejpster/statuses/111947768647434119",
"activitypub"
]
],
"content": "Idle thought: what if in Rust you were able to write:\n\npub nopanic fn foo() { … }\n\nFunctions 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.\n\nYou could also use the keyword “safe” instead of “nopanic”, leaving the default to be ?safe, or semi-safe (no UB, but could panic).",
"sig": "6cb694e37ed3a53adb8231198397c5476a34bcf33c642a42391952715eb51234c6f994a1f17139fbc9341a1b84eaf55490381a4986cf0a59df7f965ec8c034fc"
}