Skip to main content

Session

Struct Session 

Source
pub struct Session<T: ModuleResolver = DefaultModuleResolver, IO: Io = SandboxedIo<NativeIo>> { /* private fields */ }
Expand description

Evaluates queries one after another, carrying top-level let/var/def bindings and import/include directives from each query to the next.

Errors show the query they happened in, named repl#N for the Nth query, so an error in a function defined by an earlier query points at that query’s source.

let mut session = mq_lang::Session::new(mq_lang::DefaultEngine::default());
session.eval("let x = 41", mq_lang::null_input().into_iter()).unwrap();
let result = session.eval("x + 1", mq_lang::null_input().into_iter()).unwrap();
assert_eq!(result, vec![42.into()].into());

Implementations§

Source§

impl<T: ModuleResolver, IO: Io> Session<T, IO>

Source

pub fn new(engine: Engine<T, IO>) -> Self

Starts a session that evaluates queries on engine.

Source

pub fn engine(&self) -> &Engine<T, IO>

The engine queries run on.

Source

pub fn engine_mut(&mut self) -> &mut Engine<T, IO>

The engine queries run on, e.g. to define values or load modules.

Source

pub fn into_engine(self) -> Engine<T, IO>

Ends the session, returning its engine.

Source

pub fn eval<I: Iterator<Item = RuntimeValue>>( &mut self, code: &str, input: I, ) -> MqResult

Evaluates code with the bindings and modules of the queries before it.

Trait Implementations§

Source§

impl<T: Debug + ModuleResolver, IO: Debug + Io> Debug for Session<T, IO>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T = DefaultModuleResolver, IO = SandboxedIo> !RefUnwindSafe for Session<T, IO>

§

impl<T = DefaultModuleResolver, IO = SandboxedIo> !Send for Session<T, IO>

§

impl<T = DefaultModuleResolver, IO = SandboxedIo> !Sync for Session<T, IO>

§

impl<T = DefaultModuleResolver, IO = SandboxedIo> !UnwindSafe for Session<T, IO>

§

impl<T, IO> Forget for Session<T, IO>

§

impl<T, IO> Freeze for Session<T, IO>
where Engine<T, IO>: Freeze,

§

impl<T, IO> Move for Session<T, IO>

§

impl<T, IO> Unpin for Session<T, IO>
where Engine<T, IO>: Unpin,

§

impl<T, IO> UnsafeUnpin for Session<T, IO>
where Engine<T, IO>: UnsafeUnpin,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.