Comments
// single-line
/// doc comment
/* block
/* nested */
still a comment */
Strings
let s = "hello, {name}!"
let raw = r"C:\path\to\file"
let multi = r#"quotes "inside" are fine"#
let bytes = b"\x00\xFF"
Numbers
let a: u64 = 42_u64
let b = 0xFF_i32
let c = 0b1010_1100
let d = 3.14_f32
let e = 1_000_000
Functions and pipelines
#[caps(io, net)]
@inline
fn fibonacci(n: u64) -> u64 {
if n < 2 { return n }
fibonacci(n - 1) + fibonacci(n - 2)
}
pub fn main() -> Result {
let xs = [1, 2, 3, 4]
xs |> map(fibonacci) |> sum()
}
Types, enums, and traits
enum Shape {
Circle(f64),
Rect { w: f64, h: f64 },
}
trait Area {
fn area(self) -> f64
}
impl Area for Shape {
fn area(self) -> f64 {
match self {
Shape::Circle(r) => 3.14159 * r * r,
Shape::Rect { w, h } => w * h,
}
}
}
Actors and capabilities
actor Logger {
let mut buffer: Vec<string> = []
#[caps(io)]
fn log(msg: str) {
self.buffer.push(msg)
}
}