Crate exers

source ·
Expand description

Exers

Exers is a tool for compiling and running code in various languages and runtimes.

Support

Currently supported languages can be found in compilers module. And supported runtimes can be found in runtimes module.

Usage

This crate provides two main elements:

Each compiler implements some kind of Compiler trait.
Some of them may not support all runtimes, so I recommend checking the documentation of each compiler. Compilers also have some kind of config object, which is used to configure the compiler.
All compiler configs implement Default trait, so you can use Default::default() to get default config.

Each runtime implements some kind of CodeRuntime trait. Runtimes also have some kind of config object, which is used to configure the runtime.
All runtime configs implement Default trait, so you can use Default::default() to get default config.

Compilers return CompiledCode<R: CodeRuntime> object, which contains executable file (in temporary directory) and additional data for the runtime.

Runtimes take CompiledCode<R: CodeRuntime> object and run it.

Example

// Create compiler.
let compiler = RustCompiler;

// Create runtime.
let runtime = NativeRuntime;

// Our code
let code = r#"
    fn main() {
       println!("Hello, world!");
    }
"#;

// Compile the code. Code can be any kind of object that implements (Read)[std::io::Read] trait.
let compiled = compiler.compile(&mut code.as_bytes(), Default::default()).unwrap();
     
// Run the code. Native runtime just runs the executable file.
let result = runtime.run(&compiled, Default::default()).unwrap();

// Print the result.
println!("stdout: {}", result.stdout.unwrap());

Modules

  • This module contains common code for all compilers / runtimes.
  • Module containing all compilers. Currently supported compilers are:
  • Runtimes for running code.