Skip to main content

exers/
lib.rs

1//! # Exers
2//! Exers is a tool for compiling and running code in various languages and runtimes.
3//!
4//! ## Support
5//! Currently supported languages can be found in [compilers](crate::compilers) module.
6//! And supported runtimes can be found in [runtimes](crate::runtimes) module.
7//!
8//! ## Usage
9//! This crate provides two main elements:
10//! - [Compilers](crate::compilers) - for compiling code
11//! - [Runtimes](crate::runtimes) - for running code
12//!
13//! Each compiler implements some kind of [Compiler](crate::compilers::Compiler) trait. <br/>
14//! Some of them may not support all runtimes, so I recommend checking the documentation of each compiler.
15//! Compilers also have some kind of config object, which is used to configure the compiler. <br/>
16//! All compiler configs implement [Default](std::default::Default) trait, so you can use `Default::default()` to get default config.
17//!
18//! Each runtime implements some kind of [CodeRuntime](crate::runtimes::CodeRuntime) trait.
19//! Runtimes also have some kind of config object, which is used to configure the runtime. <br/>
20//! All runtime configs implement [Default](std::default::Default) trait, so you can use `Default::default()` to get default config.
21//!
22//! Compilers return [`CompiledCode<R: CodeRuntime>`](crate::compilers::CompiledCode) object,
23//! which contains executable file (in temporary directory) and additional data for the runtime.
24//!
25//! Runtimes take [`CompiledCode<R: CodeRuntime>`](crate::compilers::CompiledCode) object and run it.
26//!
27//! ## Example
28//! ```ignore
29//! // Create compiler.
30//! let compiler = RustCompiler;
31//!
32//! // Create runtime.
33//! let runtime = NativeRuntime;
34//!
35//! // Our code
36//! let code = r#"
37//!     fn main() {
38//!        println!("Hello, world!");
39//!     }
40//! "#;
41//!
42//! // Compile the code. Code can be any kind of object that implements (Read)[std::io::Read] trait.
43//! let compiled = compiler.compile(&mut code.as_bytes(), Default::default()).unwrap();
44//!     
45//! // Run the code. Native runtime just runs the executable file.
46//! let result = runtime.run(&compiled, Default::default()).unwrap();
47//!
48//! // Print the result.
49//! println!("stdout: {}", result.stdout.unwrap());
50//! ```
51
52#![allow(clippy::clone_double_ref, clippy::uninlined_format_args)]
53
54pub mod common;
55pub mod compilers;
56pub mod runtimes;