logoalt Hacker News

stusmall • yesterday at 10:01 PM • 2 replies • view on HN

You can. Something like toggle is nice because it is very clear at a glance. That's a subjective style call.

But under the hood it's all the same https://doc.rust-lang.org/stable/src/core/bool.rs.html#157-1...


Replies

dxxvi • today at 12:15 AM

Is x = !x faster than x.toggle() because from my naked eyes no function is called? Or does the compiler know that the function toggle should be replace with `!=`? If the compiler does know that, how is that knowledge implemented? Is there a table of special functions that should be replaced with something else? Or some more clever way?

➕ show 1 reply
rauli_ • yesterday at 10:34 PM

For someone who has decades of experience from other programming languages this does not look clear to me at all but rather confusing. Calling an method can change value of variable of primitive type?

➕ show 5 replies