Guide

Rust

A .qwer or .rs (since 0.7) file is Rust, and a program uses it as it uses a .qwe file: its top-level pub fns are the program's functions. The two extensions are the same to Quillo: .rs is the one editors, rustfmt and clippy know, and .qwer is the catalog's and quillo install's. A .rs file is the program's only when a use or import names it (use "imaging.rs", import imaging.rs use brightness), so a crate's own src/*.rs beside the program is left alone. Here is imaging.qwer:

//! effects: fs//! [dependencies]//! image = { version = "0.25", default-features = false, features = ["jpeg"] }/// How bright a picture is, from 0 to 255.pub fn brightness(path: &str) -> Result<f64, String> {    let img = image::open(path).map_err(|e| e.to_string())?.to_luma8();    Ok(img.pixels().map(|p| p.0[0] as f64).sum::<f64>() / img.len() as f64)}
use "imaging.qwer"route GET /photos/:name = { brightness: brightness(`photos/${name}.jpg`)? }

How it runs:

See rust.qwe and rust.qwer.

Plugins from the catalog

quillolang.org/plugins has .qwer files ready to use, each with a version, an example, and a test run before it is published. quillo install puts them beside the program (its options are below):

quillo install csv qr jwt          # csv.qwer, qr.qwer and jwt.qwer, into this folderquillo install csv --example       # and csv.qwe, its example programquillo install --update            # the plugins here that the catalog has newerquillo install --list pdf          # what the catalog has, matching "pdf"

Other stores

db is for SQL databases. For another kind (Redis, MongoDB, a graph database), use its crate in a .qwer file: its functions are the driver, and the program calls them like any other. A count of visits in Redis:

//! effects: db, env//! [dependencies]//! redis = "0.27"use std::sync::OnceLock;/// The client, made on the first call (`REDIS_URL`, or Redis on this machine).fn client() -> Result<&'static redis::Client, String> {    static C: OnceLock<redis::Client> = OnceLock::new();    if let Some(c) = C.get() {        return Ok(c);    }    let url = std::env::var("REDIS_URL").unwrap_or_else(|_| "redis://127.0.0.1/".into());    let c = redis::Client::open(url).map_err(|e| e.to_string())?;    Ok(C.get_or_init(|| c))}/// The value at `key`, or null.pub fn cache_get(key: &str) -> Result<Option<String>, String> {    let mut con = client()?.get_connection().map_err(|e| e.to_string())?;    redis::cmd("GET").arg(key).query(&mut con).map_err(|e| e.to_string())}/// Adds one to the number at `key`, and gives the new number.pub fn cache_incr(key: &str) -> Result<i64, String> {    let mut con = client()?.get_connection().map_err(|e| e.to_string())?;    redis::cmd("INCR").arg(key).query(&mut con).map_err(|e| e.to_string())}
use "redis.qwer"server fn visits(page: str) -> int {    watch(`visits:${page}`)                  // live pages showing this follow the topic    int(cache_get(`visits:${page}`)? ?? "0")}server fn visit(page: str) {    let n = cache_incr(`visits:${page}`)?    publish(`visits:${page}`)                // and refresh when it changes    n}component Visits(page: str) {    state n = live(visits, page)    <button onclick={() => visit(page)}>{n} visits</button>}
Thread
14Useful? Like it, or add to its thread below.

Thread 0 posts

On Rust: questions, tips, corrections, and code that uses it.

No posts yet. The first one opens the thread.

    Edit this page on GitHub · made from the user guide · questions on Discord or r/quillo