Files
tree-sitter-rune/examples/comprehensive.rn

88 lines
1.4 KiB
Plaintext

use std::collections;
struct Point { x, y }
struct Wrapper(inner);
enum Shape {
Circle(radius),
Rectangle { width, height },
Unknown,
}
pub fn describe(shape) {
match shape {
Shape::Circle(r) => `circle with radius ${r}`,
Shape::Rectangle { width, height } => {
let area = width * height;
`rectangle with area ${area}`
},
_ => "unknown shape",
}
}
pub async fn fetch_data(url) {
let response = http::get(url).await;
response
}
fn fibonacci() {
let a = 0;
let b = 1;
loop {
yield a;
let c = a + b;
a = b;
b = c;
}
}
pub fn make_counter() {
let count = 0;
let increment = || {
count = count + 1;
count
};
increment
}
fn check_type(value) {
if value is String {
println!("it's a string");
}
if value is not Vec {
println!("not a vector");
}
}
fn objects() {
let config = #{
name: "test",
debug: true,
count: 42,
};
}
async fn race_futures(a, b) {
select {
result = a => result,
result = b => result,
}
}
pub fn refresh() {
let items = [];
items.push(Item::new("id", "name", "cmd")
.description("A description")
.icon("icon-name")
.keywords(["one", "two"]));
items
}
pub fn query(q) {
[]
}