Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Cargo projects

Put .rk files where Cargo expects .rs files. These commands transpile every .rk file under src, examples, tests, and benches, plus build.rk, to a .rs file beside it, then run the same Cargo command:

renk build
renk check
renk run
renk test
renk clippy
renk doc
renk bench
renk cargo ARGS...  # any other cargo command, as cargo ARGS...

A generated file starts with // @generated by renk; do not edit. and is rewritten only when its content changes. renk stops with an error instead of overwriting a .rs file without that header.

src/main.rk:

fn main():
    println!("{double(21)}")

fn double(n: i32) -> i32 = n * 2

#[cfg(test)]
mod tests:
    #[test]
    fn doubles():
        assert_eq!(super.double(2), 4)

renk run prints 42, and renk test runs doubles. mod name without a body declares a module file, as mod name; does in Rust.

Diagnostics

  • Compiler diagnostics about generated files point at the .rk line and column and quote the .rk source. Diagnostics about other files print as rustc renders them.
  • rustc’s suggested replacements are Rust code, so they are left out of .rk spans.
  • --message-format=short prints src/main.rk:LINE:COLUMN: error: ... lines. --message-format=json... prints cargo’s JSON messages with spans, quoted lines, and rendered text moved to the .rk file.
  • Panic messages and backtraces from renk run, renk test, and renk bench show .rk locations. A program whose output is a terminal still writes to a terminal.
  • A name that does not resolve at a.b gets a help line saying how renk read the dot. See Limits.