Compiling with -C opt-level=3
in godbolt gives:
example::f1:
push rbp
mov rbp, rsp
xor dil, 1
or dil, sil
mov eax, edi
pop rbp
ret
Which looks comparable to the C++ version. See Lukas Kalbertodt's answer for more explanation.
Note: I had to make the function pub extern
to stop the compiler optimising it to nothing, as it is unused.