Struct felys::Worker

source ·
pub struct Worker { /* private fields */ }
Expand description

Core interpreter entry point

Implementations§

source§

impl Worker

source

pub fn new( mixin: HashMap<String, Object>, timeout: f64, maxcall: usize, lang: Language, ) -> Self

Configure and initialize a new worker

Examples found in repository?
examples/basic.rs (line 17)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
fn main() {
    let code = "print('Hello, World');".to_string();

    // your customized built-in values and rust functions
    let mixin = HashMap::from([
        ("print".into(), Object::Rust(print))
    ]);

    // init the worker with mixin
    // no timeout
    // max recursive call is 100
    // English mode
    let mut main = Worker::new(mixin, 0.0, 100, Language::EN);
    if let Err(e) = main.exec(code) {
        println!("{}", e)
    }
}
source

pub fn exec(&mut self, code: String) -> Result<Summary, Error>

Execute code and flush the global variable scope

Examples found in repository?
examples/basic.rs (line 18)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
fn main() {
    let code = "print('Hello, World');".to_string();

    // your customized built-in values and rust functions
    let mixin = HashMap::from([
        ("print".into(), Object::Rust(print))
    ]);

    // init the worker with mixin
    // no timeout
    // max recursive call is 100
    // English mode
    let mut main = Worker::new(mixin, 0.0, 100, Language::EN);
    if let Err(e) = main.exec(code) {
        println!("{}", e)
    }
}

Auto Trait Implementations§

§

impl Freeze for Worker

§

impl RefUnwindSafe for Worker

§

impl Send for Worker

§

impl Sync for Worker

§

impl Unpin for Worker

§

impl UnwindSafe for Worker

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>,

§

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>,

§

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.