Appendix B: Operators and Symbols
This appendix provides a quick reference for all operators in Oxide, including their precedence and Oxide-specific operators.
Operator Precedence Table
Operators are listed from highest precedence (evaluated first) to lowest (evaluated last).
| Precedence | Operators | Description | Associativity |
|---|---|---|---|
| 1 (highest) | . | Path/field access | Left |
| 2 | () [] ? !! | Call, index, try, force unwrap | Left |
| 3 | await ! - * & &mut | Prefix operators | Right |
| 4 | as | Type cast | Left |
| 5 | * / % | Multiplication, division, remainder | Left |
| 6 | + - | Addition, subtraction | Left |
| 7 | << >> | Bit shifts | Left |
| 8 | & | Bitwise AND | Left |
| 9 | ^ | Bitwise XOR | Left |
| 10 | | | Bitwise OR | Left |
| 11 | == != < > <= >= | Comparisons | Requires parentheses |
| 12 | && | Logical AND | Left |
| 13 | || | Logical OR | Left |
| 14 | ?? | Null coalescing | Left |
| 15 | .. ..= | Range operators | Requires parentheses |
| 16 | = += -= *= /= %= &= |= ^= <<= >>= | Assignment | Right |
| 17 (lowest) | return break continue | Control flow | Right |
Operators by Category
Arithmetic Operators
| Operator | Description | Example |
|---|---|---|
+ | Addition | 5 + 3 |
- | Subtraction | 10 - 4 |
* | Multiplication | 6 * 7 |
/ | Division | 20 / 4 |
% | Remainder | 17 % 5 |
- | Negation (unary) | -42 |
Comparison Operators
| Operator | Description | Example |
|---|---|---|
== | Equal to | x == 5 |
!= | Not equal to | x != y |
< | Less than | x < y |
> | Greater than | x > y |
<= | Less than or equal | x <= 5 |
>= | Greater than or equal | x >= 10 |
Logical Operators
| Operator | Description | Example |
|---|---|---|
&& | Logical AND (short-circuit) | a && b |
|| | Logical OR (short-circuit) | a || b |
! | Logical NOT | !a |
Bitwise Operators
| Operator | Description | Example |
|---|---|---|
& | Bitwise AND | a & b |
| | Bitwise OR | a | b |
^ | Bitwise XOR | a ^ b |
<< | Left shift | a << 2 |
>> | Right shift | a >> 2 |
Reference Operators
| Operator | Description | Example |
|---|---|---|
& | Create shared reference | &value |
&mut | Create mutable reference | &mut value |
* | Dereference | *ptr |
Assignment Operators
| Operator | Equivalent |
|---|---|
= | Assign |
+= | x = x + y |
-= | x = x - y |
*= | x = x * y |
/= | x = x / y |
%= | x = x % y |
&= |= ^= <<= >>= | Bitwise compound assignment |
Range Operators
| Operator | Description | Example |
|---|---|---|
.. | Exclusive range | 0..5 (0 to 4) |
..= | Inclusive range | 1..=5 (1 to 5) |
Oxide-Specific Operators
Null Coalescing (??)
Provides a default value when the left-hand side is null.
let name = userName ?? "Anonymous"
let config = Config.load() ?? Config.default()
CRITICAL:
??works withOption<T>ONLY, NOTResult<T, E>// This will NOT compile: let value: Result<Int, Error> = Err(someError) let result = value ?? 0 // ERROR: ?? only works with Option<T>Why?
Result<T, E>contains typed error information that should not be silently discarded. Using??would hide important error details.For Result, use explicit methods:
let value = riskyOperation().unwrapOr(default) let value = riskyOperation().unwrapOrElse { err -> handleError(err) }
Rust equivalent: .unwrap_or() or .unwrap_or_else()
Force Unwrap (!!)
Forcefully unwraps an optional value. Panics if null.
let user = findUser(id)!! // Panics if null
Rust equivalent: .unwrap()
Warning: Use sparingly. Prefer
if let, pattern matching, or??when possible.
Prefix Await
Oxide uses prefix await (unlike Rust's postfix .await).
let data = await fetchData()
let response = await client.get(url).send()?
Precedence: await binds tighter than ?, so await expr? means (await expr)?
Rust equivalent: expr.await
Try Operator (?)
Unchanged from Rust. Propagates errors in Result or Option returning functions.
fn readConfig(): Result<Config, Error> {
let content = std.fs.readToString("config.toml")?
Ok(parseConfig(content)?)
}
Symbols and Delimiters
| Symbol | Usage |
|---|---|
{ } | Blocks, closures, struct/enum bodies |
( ) | Grouping, function parameters, tuples |
[ ] | Array literals, indexing |
< > | Generic type parameters |
#[ ] | Attributes |
. | Field access, method call, path separator |
: | Type annotation, return type |
-> | Closure params, match arms |
, | List separator |
; | Statement terminator (optional) |
Summary: Differences from Rust
| Oxide | Rust | Description |
|---|---|---|
?? | .unwrap_or() | Null coalescing (Option only) |
!! | .unwrap() | Force unwrap |
await expr | expr.await | Prefix await |
. | :: | Path separator |
: | -> | Return type annotation |
-> | => | Match arm, closure params |
IMPORTANT: The Rust operators in the right column (
::,->for return types,=>for match arms) are not valid Oxide syntax. These are grammar changes, not style preferences. Using::in Oxide code will result in a syntax error. Oxide uses.as its only path separator.