Executor

Struct Executor 

Source
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§

Source§

impl Executor

Source

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
§Example
let executor = piston_rs::Executor::new();

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

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());
Source

pub fn set_language(self, language: &str) -> Self

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());
Source

pub fn set_version(self, version: &str) -> Self

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());
Source

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());
Source

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);
Source

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());
Source

pub fn set_stdin(self, stdin: &str) -> Self

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());
Source

pub fn add_arg(self, arg: &str) -> Self

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()]);
Source

pub fn add_args(self, args: Vec<&str>) -> Self

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()]);
Source

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());
Source

pub fn set_compile_timeout(self, timeout: isize) -> Self

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);
Source

pub fn set_run_timeout(self, timeout: isize) -> Self

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);
Source

pub fn set_compile_memory_limit(self, limit: isize) -> Self

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);
Source

pub fn set_run_memory_limit(self, limit: isize) -> Self

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§

Source§

impl Clone for Executor

Source§

fn clone(&self) -> Executor

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Executor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Executor

Source§

fn default() -> Self

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("*"));
Source§

impl<'de> Deserialize<'de> for Executor

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Executor

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,