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).

PrecedenceOperatorsDescriptionAssociativity
1 (highest).Path/field accessLeft
2() [] ? !!Call, index, try, force unwrapLeft
3await ! - * & &mutPrefix operatorsRight
4asType castLeft
5* / %Multiplication, division, remainderLeft
6+ -Addition, subtractionLeft
7<< >>Bit shiftsLeft
8&Bitwise ANDLeft
9^Bitwise XORLeft
10|Bitwise ORLeft
11== != < > <= >=ComparisonsRequires parentheses
12&&Logical ANDLeft
13||Logical ORLeft
14??Null coalescingLeft
15.. ..=Range operatorsRequires parentheses
16= += -= *= /= %= &= |= ^= <<= >>=AssignmentRight
17 (lowest)return break continueControl flowRight

Operators by Category

Arithmetic Operators

OperatorDescriptionExample
+Addition5 + 3
-Subtraction10 - 4
*Multiplication6 * 7
/Division20 / 4
%Remainder17 % 5
-Negation (unary)-42

Comparison Operators

OperatorDescriptionExample
==Equal tox == 5
!=Not equal tox != y
<Less thanx < y
>Greater thanx > y
<=Less than or equalx <= 5
>=Greater than or equalx >= 10

Logical Operators

OperatorDescriptionExample
&&Logical AND (short-circuit)a && b
||Logical OR (short-circuit)a || b
!Logical NOT!a

Bitwise Operators

OperatorDescriptionExample
&Bitwise ANDa & b
|Bitwise ORa | b
^Bitwise XORa ^ b
<<Left shifta << 2
>>Right shifta >> 2

Reference Operators

OperatorDescriptionExample
&Create shared reference&value
&mutCreate mutable reference&mut value
*Dereference*ptr

Assignment Operators

OperatorEquivalent
=Assign
+=x = x + y
-=x = x - y
*=x = x * y
/=x = x / y
%=x = x % y
&= |= ^= <<= >>=Bitwise compound assignment

Range Operators

OperatorDescriptionExample
..Exclusive range0..5 (0 to 4)
..=Inclusive range1..=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 with Option<T> ONLY, NOT Result<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

SymbolUsage
{ }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

OxideRustDescription
??.unwrap_or()Null coalescing (Option only)
!!.unwrap()Force unwrap
await exprexpr.awaitPrefix 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.