Below are the operators in Rust.
| Macro | Explanation | Usage |
| ! | Macro expansion | ident!(...) ident!{…} ident![…] |
| == | Equality comparison | expr == expr |
| ≠ | Nonequality comparison | var ≠ expr |
| < | Less than comparison | expr < expr |
| ≤ | Less than or equal to comparison | expr ≤ expr |
| > | Greater than comparison | expr > expr |
| ≥ | Greater than or equal to comparison | expr ≥ expr |
| + | Arithmetic addition | expr + expr |
| += | Arithmetic addition and assignment | var += expr |
| - | Arithmetic negation | -expr |
| - | Arithmetic subtraction | expr - expr |
| -= | Arithmetic subtraction and assignment | var -= expr |
| * | Arithmetic multiplication | expr * expr |
| *= | Arithmetic multiplication and assignment | var *= expr |
| / | Arithmetic division | expr / expr |
| /= | Arithmetic division and assignment | var /= expr |
| % | Arithmetic remainder | expr % expr |
| %= | Arithmetic remainder and assignment | var %= expr |
| ! | Bitwise or logical complement | !expr |
| & | Bitwise AND | expr & expr |
| &= | Bitwise AND and assignment | var &= expr |
| | | Bitwise OR | expr | expr |
| |= | Bitwise OR and assignment | var |= expr |
| ^ | Bitwise exclusive OR | expr ^ expr |
| ^= | Bitwise exclusive OR and assignment | var ^= expr |
| && | Short-circuiting logical AND | expr && expr |
| || | Short-circuiting logical OR | expr || expr |
| & | Borrow | &expr &mut expr |
| & | Borrowed pointer type | &type &mut type &’a type &’a mut type |
| * | Dereference | *expr |
| * | Raw pointer | *const type *mut type |
| + | Compound type constraint | trait + trait ’a + trait |
| , | Argument and element separator | expr, expr |
| → | Function and closure return type | fn(…) → type |…| → type |
| . | Member access | expr.ident |
| .. | Right-exclusive range literal | .. expr.. ..expr expr..expr |
| ..= | Right-inclusive range literal | ..=expr expr..=expr |
| .. | Struct literal update syntax | ..expr |
| .. | "And the rest” pattern binding | variant(x, ..) struct_type { x, .. } |
| : | Constraints | pat: type ident: type |
| : | Struct field initializer | ident: expr |
| : | Loop label | ‘a: loop {…} |
| ; | Statement and item terminator | expr; |
| ; | Part of fixed-size array syntax | […; len] |
| << | Left-shift | expr << expr |
| <<= | Left-shift and assignment | var <<= expr |
| >> | Right-shift | expr >> expr |
| >>= | Right-shift and assignment | var >>= expr |
| = | Assignment/Equivalence | var = expr ident = type |
| ⇒ | Part of match arm syntax | pat ⇒ expr |
| @ | Pattern binding | ident @ pat |
| | | Pattern alternatives | pat | pat |
| ? | Error propagation | expr? |
반응형
'Rust' 카테고리의 다른 글
| [Rust] Function (2) | 2022.08.01 |
|---|---|
| [Rust] Control Flow (0) | 2022.07.31 |
| [Rust] Data Type (0) | 2022.07.30 |
| [Rust] Variables (0) | 2022.07.28 |
| [Rust] Getting Started Rust with VS Code (0) | 2022.07.26 |
댓글