ralfbiedert / cheats.rs

Rust Language Cheat Sheet - https://cheats.rs
https://cheats.rs
4.14k stars 395 forks source link

Bit wise operations missing? #151

Open doronbehar opened 2 years ago

doronbehar commented 2 years ago

I'm a bit new to rust and I encountered the symbol << which I wanted to know what does it mean and I didn't found it on the website. It'd be great if it was added in a proper location, with a link to here:

https://doc.rust-lang.org/stable/std/ops/trait.Shr.html

Thanks a lot for maintaining this website.

ShadowJonathan commented 2 years ago

I would also like to see this, in other languages I haven't used these operations much, and knowing how they (could) behave on rust would be nice.

ralfbiedert commented 2 years ago

Thanks for the feedback. My reasoning so far has been documenting "common operators one would know coming from another language" does not really explain anything to our target audience (experienced programmers, new to Rust) and just takes up space.

That said, you have a point that there's value documenting their behavior w.r.t. Rust specifics. How about something like this:

Operator Description
a + b Invokes Add<B> on A. Integers overflow in release builds or turn panics in debug.

PRs welcome. I think a quick mock would be good to get a feeling for much much wall-of-text that becomes if done with all operators; but as long as it looks good (TM) I can see this getting merged.

ShadowJonathan commented 2 years ago

Ah, i think documenting "rust operands are just invoked traits" with a table like that would be really useful onto itself, actually :eyes:

mattrobineau commented 2 years ago

@doronbehar I was just looking at bitwise operators last night.

@ralfbiedert What about using the Table B-1 from the rust book?

ralfbiedert commented 2 years ago

What about using the Table B-1 from the rust book?

I don't think that table fits as-is, I'd still start experimenting with some format mentioned above.

glasser commented 1 year ago

On a related note, while I agree that it's reasonable to expect users to be familiar with the standard operators, it might be nice to at list them really compactly. For example, it's not too uncommon to use and and or rather than && and || for logical operators these days (eg Python), and it might not be to strange to wonder if Rust has an exponentiation operator or distinct division operators for rounding vs not. Even just a section that lists the main operators in groups like "logical", "bitwise", "arithmetic", etc without documenting each symbol individually could be nice?

That is, I think there's value in saying "these are the Rust operators, you can probably guess what they do" rather than just "Rust probably has the operators that you might imagine exist".

ralfbiedert commented 1 year ago

That is, I think there's value in saying "these are the Rust operators, you can probably guess what they do" rather than just "Rust probably has the operators that you might imagine exist".

Yes good point. Right now the main thing that's missing is a good idea how to write and layout that table so it "blends in". I once tried the obvious

x + y     Adds x and y.
...

But that got tedious real fast.