Skip to content

Rust Port

Sirui Mu edited this page Oct 26, 2019 · 1 revision

The core logic of WaveTestLib is written in Rust, and it's natural to use the Rust port to write your answer checkers and interactors in Rust. The Rust implementation is maintained under src/rust directory. Without further comments, all shell commands listed in this page assume that you are in this directory.

Build

Before build, please make sure that you have cargo installed in your environment:

cargo --version

If not, it's recommended to install cargo through rustup, which installs the necessary Rust toolchain to build WaveTestLib. For instructions on installing rustup, please visit here.

Build Source Documentation

Use the following command to build source documentation and open it in your browser:

cargo doc --open

Build Library Binary

Use the following command to build the rust port of WaveTestLib into a static library:

cargo build

The static library file will be available at target/<config>/libwave_test_lib.a. <config> will be either debug or release depending on your configuration.

Install

You need to install the Rust port of WaveTestLib into your Rust environment before using it in your answer checker or interactor project:

cargo install

Then add the following line to your Cargo.toml:

[dependencies]
wave_test_lib="0.1"

And you're ready to go.

Usage

Quick Tutorial

Checker

The following code is a ready-to-work version of an answer checker that compares each floating point numbers produced by the user's program against the ones in the standard answer file, with an absolute tolerance of 1e-8:

extern crate wave_test_lib;

fn main() {
    let checker = wave_test_lib::Checker::new();
    let std_ans = checker.std_answer();
    let usr_ans = checker.user_answer();
    
    while let Some(expected) = std_ans.read_token_as::<f64>() {
        usr_ans.expect_float_eq(expected, 1e-8);
    }

    usr_ans.expect_eof();
}

Interactor

To be updated.

Clone this wiki locally