Core Types
Simplex provides a set of built-in primitive types for common operations.
Numeric Types
| Type | Description | Example |
|---|---|---|
i64 |
64-bit signed integer | let x: i64 = 42 |
i32 |
32-bit signed integer | let x: i32 = 42 |
f64 |
64-bit floating point | let x: f64 = 3.14 |
f32 |
32-bit floating point | let x: f32 = 3.14 |
Text and Boolean
| Type | Description | Example |
|---|---|---|
String |
UTF-8 encoded text | let s = "hello" |
Bool |
Boolean value | let b = true |
Char |
Single Unicode character | let c = 'a' |
Collections
List<T>
An ordered, growable collection of elements.
let items = [1, 2, 3]
items.len() // 3
items.push(4) // [1, 2, 3, 4]
items.pop() // Some(4)
items.map(x => x * 2) // [2, 4, 6]
items.filter(x => x > 1) // [2, 3]
items.reduce(0, (a, b) => a + b) // 6
items.contains(2) // true
items.is_empty() // false
items.first() // Some(1)
items.last() // Some(3)
Map<K, V>
A key-value collection with unique keys.
let data = {"name": "Alice", "age": "30"}
data.get("name") // Some("Alice")
data.insert("city", "NYC") // adds key-value
data.remove("age") // removes key
data.contains_key("name") // true
data.keys() // ["name", "city"]
data.values() // ["Alice", "NYC"]
data.len() // 2
Set<T>
An unordered collection of unique elements.
let tags = {"rust", "ai", "web"insert("api") // adds element
tags.remove("web") // removes element
tags.contains("ai") // true
tags.union(other_set) // set union
tags.intersection(other) // set intersection
Actor Functions
Functions for working with actors and message passing.
| Function | Description | Returns |
|---|---|---|
spawn T |
Create a new actor instance | ActorRef<T> |
send(actor, msg) |
Send message (fire-and-forget) | () |
ask(actor, msg) |
Send message and wait for reply | T |
ask_async(actor, msg) |
Send message, get future | Future<T> |
checkpoint() |
Persist actor state | () |
stop(actor) |
Gracefully stop an actor | () |
AI Primitives
Built-in functions for AI operations.
ai::complete
// Generate text completion
let response = await ai::complete(prompt)
// With model tier
let response = await ai::complete(prompt, model: "quality")
ai::extract<T>
// Extract structured data into a type
struct Person { name: String, age: i64 }
let person = await ai::extract<Person>(text)
ai::classify<T>
// Classify into enum variants
enum Sentiment { Positive, Negative, Neutral }
let sentiment = await ai::classify<Sentiment>(text)
ai::embed
// Generate embedding vector
let embedding: Vector<f32> = ai::embed(text)
I/O Operations
| Function | Description |
|---|---|
print(msg) |
Print to stdout |
println(msg) |
Print with newline |
read_file(path) |
Read file contents |
write_file(path, content) |
Write to file |
http::get(url) |
HTTP GET request |
http::post(url, body) |
HTTP POST request |
Concurrency
| Function | Description |
|---|---|
await future |
Wait for async operation |
parallel(futures...) |
Run futures concurrently, wait for all |
race(futures...) |
Return first completed future |
timeout(duration, future) |
Add timeout to future |
sleep(duration) |
Pause execution |
Error Handling
Option<T>
let maybe: Option<i64> = Some(42)
maybe.unwrap() // 42 (panics if None)
maybe.unwrap_or(0) // 42 (returns 0 if None)
maybe.is_some() // true
maybe.is_none() // false
maybe.map(x => x * 2) // Some(84)
Result<T, E>
let result: Result<i64, Error> = Ok(42)
result.unwrap() // 42 (panics if Err)
result.unwrap_or(0) // 42 (returns 0 if Err)
result.is_ok() // true
result.is_err() // false
// Propagate errors with ?
fn process() -> Result<Data, Error> {
let data = load_data()? // returns early if Err
Ok(transform(data))
}
Full Documentation
For complete API documentation including all modules and detailed examples, visit the GitHub repository.