Appendix A: Keywords

The Oxide programming language uses a combination of Oxide-specific keywords and keywords shared with Rust. This appendix lists all keywords and provides information about their usage.

Oxide-Specific Keywords

These keywords are unique to Oxide or have different semantics from their Rust counterparts:

KeywordCategoryRust EquivalentDescription
varBindinglet mutMutable variable binding. Declares a variable that can be reassigned.
publicVisibilitypubPublic visibility modifier. Makes items accessible from outside the current module.
importModuleuseModule imports. Brings items from other modules into scope.
externalModule(with module) mod X;External module declaration. Declares a module whose body is in a separate file.
moduleModulemodModule definition. Defines a module either inline or as an external reference.
extensionImplementationimplType extension/implementation. Adds methods to a type or implements a trait for a type.
guardControl Flow(no direct equivalent)Early return guard. Ensures a condition holds or executes a diverging else block.
mutatingMethod Modifier&mut selfMutable method modifier. Indicates the method borrows self mutably.
consumingMethod ModifierselfConsuming method modifier. Indicates the method takes ownership of self.
staticMethod Modifier(no self)Static method modifier. Indicates the method has no self parameter.
nullLiteralNoneNull literal. Represents the absence of a value in nullable types (T?).

Detailed Usage

var - Mutable Variable Binding

var counter = 0
counter += 1  // Allowed because counter is mutable

var items: Vec<String> = vec![]
items.push("hello")

See Chapter 3.1: Variables and Mutability for more details.

public - Public Visibility

public fn createUser(name: str): User {
    User { name: name.toString() }
}

public struct Config {
    path: PathBuf,
    verbose: Bool,
}

import - Module Imports

import std.collections.HashMap
import std.fs
import anyhow.{ Result, Error }
import crate.engine.{ Action, scan }

external module - External Module Declaration

// Declares a module in a separate file (engine.ox or engine/mod.ox)
external module engine
external module config

module - Inline Module Definition

module tests {
    import super.*

    #[test]
    fn testSomething() {
        assert!(true)
    }
}

extension - Type Extension

extension Config {
    public fn validate(): Bool {
        self.path.exists()
    }
}

// Trait implementation
import std.fmt.{ Display, Formatter, Result }

extension Config: Display {
    fn fmt(f: &mut Formatter): Result {
        write!(f, "Config: \(self.path)")
    }
}

See Chapter 5.3: Method Syntax for more details.

guard - Early Return Guard

guard condition else {
    return  // Must diverge!
}

guard let user = findUser(id) else {
    return Err(anyhow!("User not found"))
}
// user is now available

See Chapter 3.5: Control Flow for more details.

mutating, consuming, static - Method Modifiers

extension Config {
    // Default: &self (immutable borrow)
    fn validate(): Bool { self.path.exists() }

    // mutating: &mut self
    mutating fn setPath(path: PathBuf) { self.path = path }

    // consuming: self (takes ownership)
    consuming fn destroy() { drop(self) }

    // static: no self parameter
    static fn load(): Config? { Self.fromFile("config.toml") }
}

null - Null Literal

let name: String? = null
let value: Int? = null

match optional {
    Some(x) -> process(x),
    null -> handleNull(),
}

See Chapter 6.3: Concise Control Flow with if let for more details.

Shared Keywords

These keywords are shared with Rust and have the same or very similar semantics:

KeywordCategoryDescription
letBindingImmutable variable binding
fnFunctionFunction definition
structTypeStructure type definition
enumTypeEnumeration type definition
traitTypeTrait definition
typeTypeType alias definition
constBindingCompile-time constant
asyncAsyncAsynchronous function modifier
awaitAsyncAwait a future (prefix in Oxide, postfix in Rust)
ifControl FlowConditional expression
elseControl FlowAlternative branch / match wildcard
matchControl FlowPattern matching expression
forControl FlowFor loop
whileControl FlowWhile loop
loopControl FlowInfinite loop
breakControl FlowBreak out of a loop
continueControl FlowContinue to next loop iteration
returnControl FlowReturn from a function
selfReferenceReference to the current instance
SelfTypeType alias for the implementing type
superModuleParent module reference
crateModuleCrate root reference
whereGenericGeneric type constraints
asConversionType casting
inControl FlowUsed in for loops
unsafeSafetyUnsafe code block or function
dynTypeDynamic trait object
moveClosureMove semantics for closures
refPatternReference pattern binding
mutModifierMutable reference or pattern binding
trueLiteralBoolean true
falseLiteralBoolean false
implImplementationRust's implementation keyword (use extension in Oxide)
pubVisibilityRust's public visibility (use public in Oxide)
useModuleRust's import keyword (use import in Oxide)
modModuleRust's module keyword (use module in Oxide)
externFFIExternal function declaration

Special Note: await

While await is shared with Rust, its position differs:

// Oxide: prefix await
let response = await client.get(url).send()?
let data = await response.json()?
#![allow(unused)]
fn main() {
// Rust: postfix .await
let response = client.get(url).send().await?;
let data = response.json().await?;
}

Oxide uses prefix await because it reads more naturally from left to right and matches the syntax of Swift, Kotlin, JavaScript, and Python.

Special Note: else in Match

In Oxide, else serves double duty as both the alternative branch in if expressions and as the wildcard pattern in match expressions:

match command {
    Command.Run -> executeRun(),
    Command.Build -> executeBuild(),
    else -> showHelp(),  // Wildcard - equivalent to Rust's _
}

Reserved Keywords

The following keywords are reserved for potential future use:

KeywordNotes
abstractReserved
becomeReserved
boxReserved
doReserved
finalReserved
macroReserved
overrideReserved
privReserved
tryReserved
typeofReserved
unsizedReserved
virtualReserved
yieldReserved

These keywords cannot be used as identifiers even though they do not currently have a defined meaning in Oxide.

Raw Identifiers

If you need to use a keyword as an identifier (for example, when interfacing with Rust code that uses reserved keywords as names), you can use the raw identifier syntax:

let r#type = "keyword"  // Uses 'type' as an identifier

Quick Reference

Keyword Mapping: Oxide to Rust

OxideRust
var x = ...let mut x = ...
public fnpub fn
import a.buse a::b;
Type.method()Type::method()
external module xmod x;
module x { }mod x { }
extension T { }impl T { }
extension T: Trait { }impl Trait for T { }
guard c else { }if !c { } or let-else
mutating fnfn(&mut self)
consuming fnfn(self)
static fnfn() (no self)
nullNone
await exprexpr.await
match { else -> }match { _ => }

IMPORTANT: The Rust syntax in the right column is NOT valid in Oxide. These are grammar changes, not style preferences. For example, :: does not exist in Oxide - using it will cause a syntax error. Oxide uses . as its only path separator.

Categories at a Glance

Bindings: let, var, const

Functions: fn, async, return

Types: struct, enum, trait, type, Self

Methods: extension, mutating, consuming, static, self

Control Flow: if, else, match, for, while, loop, break, continue, guard

Modules: import, module, external, public, super, crate

Async: async, await

Safety: unsafe

Literals: true, false, null

Modifiers: mut, ref, move, dyn, where, as, in