Struct Exec

Source
pub struct Exec { /* private fields */ }
Expand description

Interface for running brainfuck code.

The prog method returns an instance with the default options (no timeout, input or temporary file path)

input, timeout and tmpdir are used to change the default values, the program can then be run by calling run, transpile or interpret.

let prog = "++++++++++[>++++++++++>+++++++++++<<-]>++.>+..";
let output = Exec::prog(prog).run().unwrap();

assert_eq!(String::from("foo"), output);

Implementations§

Source§

impl Exec

Source

pub fn prog(prog: &str) -> Exec

Contructs a new Exec, configured to run prog. By default it will be run without input, timeout or temporary file path (defaults to cwd).

Source

pub fn input(self, input: Option<String>) -> Exec

Sets the input for the program.

Source

pub fn timeout(self, time: Option<Duration>) -> Exec

Sets the timeout for the program.

Source

pub fn tmpdir(self, tmp_path: Option<PathBuf>) -> Exec

Sets the temporary file path for the transpiler.

Source

pub fn run(self) -> Result<String, Error>

Wrapper for the transpile and interpret methods: uses the faster transpiler when rustc is detected, falls back to interpreting the code.

Source

pub fn interpret(self) -> Result<String, Error>

Runs the program with the interpreter, returning the output or an Error.

Source

pub fn transpile(self) -> Result<String, Error>

Runs the program with the transpiler, returning the output or an Error.

Needs read and write permission in the chosen temporary file folder.

Source

pub fn translate(&self) -> Result<String, Error>

Translated the program to rust code

Auto Trait Implementations§

§

impl Freeze for Exec

§

impl RefUnwindSafe for Exec

§

impl Send for Exec

§

impl Sync for Exec

§

impl Unpin for Exec

§

impl UnwindSafe for Exec

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V