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: StringRequired - The language to use for execution. Defaults to a
new String.
version: StringThe 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: StringThe 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: isizeThe maximum allowed time for compilation in milliseconds.
Defaults to 10,000.
run_timeout: isizeThe maximum allowed time for execution in milliseconds. Defaults
to 3,000.
compile_memory_limit: isizeThe maximum allowed memory usage for compilation in bytes.
Defaults to -1 (no limit).
run_memory_limit: isizeThe maximum allowed memory usage for execution in bytes.
Defaults to -1 (no limit).
Implementations§
Source§impl Executor
impl Executor
Sourcepub fn new() -> Self
pub fn new() -> Self
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
Executor- The new blank Executor.
§Example
let executor = piston_rs::Executor::new();
assert_eq!(executor.language, String::new());
assert_eq!(executor.version, String::from("*"));Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
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());Sourcepub fn set_language(self, language: &str) -> Self
pub fn set_language(self, language: &str) -> Self
Sourcepub fn set_version(self, version: &str) -> Self
pub fn set_version(self, version: &str) -> Self
Sourcepub fn add_file(self, file: File) -> Self
pub fn add_file(self, file: File) -> Self
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());Sourcepub fn add_files(self, files: Vec<File>) -> Self
pub fn add_files(self, files: Vec<File>) -> Self
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);Sourcepub fn set_files(&mut self, files: Vec<File>)
pub fn set_files(&mut self, files: Vec<File>)
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());Sourcepub fn set_args(&mut self, args: Vec<&str>)
pub fn set_args(&mut self, args: Vec<&str>)
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());