Repl

Struct Repl 

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

A small persistent REPL environment wrapper.

Notes:

  • Repl::new() creates a persistent environment and initializes built-ins.
  • Repl::eval(&self, code) evaluates the provided code in the persistent env so variables, functions and imports persist between calls.

Implementations§

Source§

impl Repl

Source

pub fn new() -> Self

Create a new persistent REPL environment (with built-ins initialized).

Source

pub fn eval<T: AsRef<str>>(&self, script: T) -> Result<Value, JSError>

Evaluate a script in the persistent environment. Returns the evaluation result or an error.

Source

pub fn is_complete_input(src: &str) -> bool

Returns true when the given input looks like a complete JavaScript top-level expression/program piece (i.e. brackets and template expressions are balanced, strings/comments/regex literals are properly closed).

This uses heuristics (not a full parser) but covers common REPL cases:

  • ignores brackets inside single/double-quoted strings
  • supports template literals and nested ${ … } expressions
  • ignores brackets inside // and /* */ comments
  • attempts to detect regex literals using a simple context heuristic and ignores brackets inside them

Trait Implementations§

Source§

impl Default for Repl

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Repl

§

impl !RefUnwindSafe for Repl

§

impl !Send for Repl

§

impl !Sync for Repl

§

impl Unpin for Repl

§

impl !UnwindSafe for Repl

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.