Unsafe Rust Functions
You can mark your own functions as unsafe
if they require particular
preconditions to avoid undefined behaviour.
Speaker Notes
We wouldn’t actually use pointers for a swap
function — it can be done
safely with references.
Note that unsafe code is allowed within an unsafe function without an unsafe
block. We can prohibit this with #[deny(unsafe_op_in_unsafe_fn)]
. Try adding
it and see what happens. This will
change in the 2024 Rust edition.