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
sourceimpl 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());sourcepub fn set_compile_timeout(self, timeout: isize) -> Self
pub fn set_compile_timeout(self, timeout: isize) -> Self
sourcepub fn set_run_timeout(self, timeout: isize) -> Self
pub fn set_run_timeout(self, timeout: isize) -> Self
sourcepub fn set_compile_memory_limit(self, limit: isize) -> Self
pub fn set_compile_memory_limit(self, limit: isize) -> Self
sourcepub fn set_run_memory_limit(self, limit: isize) -> Self
pub fn set_run_memory_limit(self, limit: isize) -> Self
Trait Implementations
sourceimpl<'de> Deserialize<'de> for Executor
impl<'de> Deserialize<'de> for Executor
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations
impl RefUnwindSafe for Executor
impl Send for Executor
impl Sync for Executor
impl Unpin for Executor
impl UnwindSafe for Executor
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber to this type, returning a
WithDispatch wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more