Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call out Neg trait in speaker notes #2072

Open
fw-immunant opened this issue May 9, 2024 · 0 comments
Open

Call out Neg trait in speaker notes #2072

fw-immunant opened this issue May 9, 2024 · 0 comments
Assignees

Comments

@fw-immunant
Copy link
Collaborator

We have a slide on the various operator traits in the standard library, which focuses on their overall design and how to implement these for our own types so we can use operator syntax with them. This is good, but there are a couple semantic surprises in how Rust operators behave, which we should note explicitly.

One is that the Neg operator (!) does not "boolify" like the C/C++/JS incarnations of this operator; it instead negates each bit of an integer, so !5u8 is 250.

Another is that the &&/|| operators are not tied to traits because they are lazy in their right-hand sides, so they cannot be used with user-defined types.

@fw-immunant fw-immunant self-assigned this May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant