pub struct Executor {
    pub language: String,
    pub version: String,
    pub files: Vec<File>,
    pub stdin: String,
    pub args: Vec<String>,
    pub compile_timeout: isize,
    pub run_timeout: isize,
    pub compile_memory_limit: isize,
    pub run_memory_limit: isize,
}
Expand description

An object containing information about the code being executed.

A convenient builder flow is provided by the methods associated with the Executor. These consume self and return self for chained calls.

Fields

language: String

Required - The language to use for execution. Defaults to a new String.

version: String

The version of the language to use for execution. Defaults to “*” (most recent version).

files: Vec<File>

Required - A Vector of File’s to send to Piston. The first file in the vector is considered the main file. Defaults to a new Vector.

stdin: String

The text to pass as stdin to the program. Defaults to a new String.

args: Vec<String>

The arguments to pass to the program. Defaults to a new Vector.

compile_timeout: isize

The maximum allowed time for compilation in milliseconds. Defaults to 10,000.

run_timeout: isize

The maximum allowed time for execution in milliseconds. Defaults to 3,000.

compile_memory_limit: isize

The maximum allowed memory usage for compilation in bytes. Defaults to -1 (no limit).

run_memory_limit: isize

The maximum allowed memory usage for execution in bytes. Defaults to -1 (no limit).

Implementations

Creates a new executor representing source code to be executed.

Metadata regarding the source language and files will need to be added using the associated method calls, and other optional fields can be set as well.

Returns
Example
let executor = piston_rs::Executor::new();

assert_eq!(executor.language, String::new());
assert_eq!(executor.version, String::from("*"));

Resets the executor back to a new state, ready to be configured again and sent to Piston after metadata is added. This method mutates the existing executor in place.

Example
let mut executor = piston_rs::Executor::new()
    .set_language("rust");

assert_eq!(executor.language, "rust".to_string());

executor.reset();

assert_eq!(executor.language, String::new());

Sets the language to use for execution.

Arguments
  • language - The language to use.
Returns
  • Self - For chained method calls.
Example
let executor = piston_rs::Executor::new()
    .set_language("rust");

assert_eq!(executor.language, "rust".to_string());

Sets the version of the language to use for execution.

Arguments
  • version - The version to use.
Returns
  • Self - For chained method calls.
Example
let executor = piston_rs::Executor::new()
    .set_version("1.50.0");

assert_eq!(executor.version, "1.50.0".to_string());

Adds a File containing the code to be executed. Does not overwrite any existing files.

Arguments
  • file - The file to add.
Returns
  • Self - For chained method calls.
Example
let file = piston_rs::File::default();

let executor = piston_rs::Executor::new()
    .add_file(file.clone());

assert_eq!(executor.files, [file].to_vec());

Adds multiple File’s containing the code to be executed. Does not overwrite any existing files.

Arguments
  • files - The files to add.
Returns
  • Self - For chained method calls.
Example
let mut files = vec![];

for _ in 0..3 {
    files.push(piston_rs::File::default());
}

let executor = piston_rs::Executor::new()
    .add_files(files.clone());

assert_eq!(executor.files, files);

Adds multiple File’s containing the code to be executed. Overwrites any existing files. This method mutates the existing executor in place. Overwrites any existing files.

Arguments
  • files - The files to replace existing files with.
Example
let old_file = piston_rs::File::default()
    .set_name("old_file.rs");

let mut executor = piston_rs::Executor::new()
    .add_file(old_file.clone());

assert_eq!(executor.files.len(), 1);
assert_eq!(executor.files[0].name, "old_file.rs".to_string());

let new_files = vec![
    piston_rs::File::default().set_name("new_file1.rs"),
    piston_rs::File::default().set_name("new_file2.rs"),
];

executor.set_files(new_files.clone());

assert_eq!(executor.files.len(), 2);
assert_eq!(executor.files[0].name, "new_file1.rs".to_string());
assert_eq!(executor.files[1].name, "new_file2.rs".to_string());

Sets the text to pass as stdin to the program.

Arguments
  • stdin - The text to set.
Returns
  • Self - For chained method calls.
Example
let executor = piston_rs::Executor::new()
    .set_stdin("Fearless concurrency");

assert_eq!(executor.stdin, "Fearless concurrency".to_string());

Adds an arg to be passed as a command line argument. Does not overwrite any existing args.

Arguments
  • arg - The arg to add.
Returns
  • Self - For chained method calls.
Example
let executor = piston_rs::Executor::new()
    .add_arg("--verbose");

assert_eq!(executor.args, vec!["--verbose".to_string()]);

Adds multiple args to be passed as a command line arguments. Does not overwrite any existing args.

Arguments
  • args - The args to add.
Example
let executor = piston_rs::Executor::new()
    .add_args(vec!["--verbose"]);

assert_eq!(executor.args, vec!["--verbose".to_string()]);

Adds multiple args to be passed as a command line arguments. Overwrites any existing args. This method mutates the existing executor in place. Overwrites any existing args.

Arguments
  • args - The args to replace existing args with.
Example
let mut executor = piston_rs::Executor::new()
    .add_arg("--verbose");

assert_eq!(executor.args.len(), 1);
assert_eq!(executor.args[0], "--verbose".to_string());

let args = vec!["commit", "-S"];
executor.set_args(args);

assert_eq!(executor.args.len(), 2);
assert_eq!(executor.args[0], "commit".to_string());
assert_eq!(executor.args[1], "-S".to_string());

Sets the maximum allowed time for compilation in milliseconds.

Arguments
  • timeout - The timeout to set.
Returns
  • Self - For chained method calls.
Example
let executor = piston_rs::Executor::new()
    .set_compile_timeout(5000);

assert_eq!(executor.compile_timeout, 5000);

Sets the maximum allowed time for execution in milliseconds.

Arguments
  • timeout - The timeout to set.
Returns
  • Self - For chained method calls.
Example
let executor = piston_rs::Executor::new()
    .set_run_timeout(1500);

assert_eq!(executor.run_timeout, 1500);

Sets the maximum allowed memory usage for compilation in bytes.

Arguments
  • limit - The memory limit to set.
Returns
  • Self - For chained method calls.
Example
let executor = piston_rs::Executor::new()
    .set_compile_memory_limit(100_000_000);

assert_eq!(executor.compile_memory_limit, 100_000_000);

Sets the maximum allowed memory usage for execution in bytes.

Arguments
  • limit - The memory limit to set.
Returns
  • Self - For chained method calls.
Example
let executor = piston_rs::Executor::new()
    .set_run_memory_limit(100_000_000);

assert_eq!(executor.run_memory_limit, 100_000_000);

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Creates a new executor. Alias for Executor::new.

Returns
Example
let executor = piston_rs::Executor::default();

assert_eq!(executor.language, String::new());
assert_eq!(executor.version, String::from("*"));

Deserialize this value from the given Serde deserializer. Read more

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more