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:
| Keyword | Category | Rust Equivalent | Description |
|---|---|---|---|
var | Binding | let mut | Mutable variable binding. Declares a variable that can be reassigned. |
public | Visibility | pub | Public visibility modifier. Makes items accessible from outside the current module. |
import | Module | use | Module imports. Brings items from other modules into scope. |
external | Module | (with module) mod X; | External module declaration. Declares a module whose body is in a separate file. |
module | Module | mod | Module definition. Defines a module either inline or as an external reference. |
extension | Implementation | impl | Type extension/implementation. Adds methods to a type or implements a trait for a type. |
guard | Control Flow | (no direct equivalent) | Early return guard. Ensures a condition holds or executes a diverging else block. |
mutating | Method Modifier | &mut self | Mutable method modifier. Indicates the method borrows self mutably. |
consuming | Method Modifier | self | Consuming method modifier. Indicates the method takes ownership of self. |
static | Method Modifier | (no self) | Static method modifier. Indicates the method has no self parameter. |
null | Literal | None | Null 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:
| Keyword | Category | Description |
|---|---|---|
let | Binding | Immutable variable binding |
fn | Function | Function definition |
struct | Type | Structure type definition |
enum | Type | Enumeration type definition |
trait | Type | Trait definition |
type | Type | Type alias definition |
const | Binding | Compile-time constant |
async | Async | Asynchronous function modifier |
await | Async | Await a future (prefix in Oxide, postfix in Rust) |
if | Control Flow | Conditional expression |
else | Control Flow | Alternative branch / match wildcard |
match | Control Flow | Pattern matching expression |
for | Control Flow | For loop |
while | Control Flow | While loop |
loop | Control Flow | Infinite loop |
break | Control Flow | Break out of a loop |
continue | Control Flow | Continue to next loop iteration |
return | Control Flow | Return from a function |
self | Reference | Reference to the current instance |
Self | Type | Type alias for the implementing type |
super | Module | Parent module reference |
crate | Module | Crate root reference |
where | Generic | Generic type constraints |
as | Conversion | Type casting |
in | Control Flow | Used in for loops |
unsafe | Safety | Unsafe code block or function |
dyn | Type | Dynamic trait object |
move | Closure | Move semantics for closures |
ref | Pattern | Reference pattern binding |
mut | Modifier | Mutable reference or pattern binding |
true | Literal | Boolean true |
false | Literal | Boolean false |
impl | Implementation | Rust's implementation keyword (use extension in Oxide) |
pub | Visibility | Rust's public visibility (use public in Oxide) |
use | Module | Rust's import keyword (use import in Oxide) |
mod | Module | Rust's module keyword (use module in Oxide) |
extern | FFI | External 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:
| Keyword | Notes |
|---|---|
abstract | Reserved |
become | Reserved |
box | Reserved |
do | Reserved |
final | Reserved |
macro | Reserved |
override | Reserved |
priv | Reserved |
try | Reserved |
typeof | Reserved |
unsized | Reserved |
virtual | Reserved |
yield | Reserved |
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
| Oxide | Rust |
|---|---|
var x = ... | let mut x = ... |
public fn | pub fn |
import a.b | use a::b; |
Type.method() | Type::method() |
external module x | mod 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 fn | fn(&mut self) |
consuming fn | fn(self) |
static fn | fn() (no self) |
null | None |
await expr | expr.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