pub struct MontyRepl<T>where
T: ResourceTracker,{ /* private fields */ }code and embedded-python only.Expand description
Stateful REPL session that executes snippets incrementally without replay.
MontyRepl preserves heap and global variable state between snippets.
Each feed() compiles and executes only the new snippet against the current
state, avoiding the cost and semantic risks of replaying prior code.
Implementations§
Source§impl<T> MontyRepl<T>where
T: ResourceTracker,
impl<T> MontyRepl<T>where
T: ResourceTracker,
Sourcepub fn new(
script_name: &str,
resource_tracker: T,
options: CompileOptions,
) -> MontyRepl<T>
pub fn new( script_name: &str, resource_tracker: T, options: CompileOptions, ) -> MontyRepl<T>
Creates an empty REPL session with no code parsed or executed.
All code execution is driven through feed_run() or feed_start(). This separates
construction from execution, matching the pattern used by MontyRun::new().
The CompileOptions apply to every snippet fed to the session.
Sourcepub fn tracker(&self) -> &T
pub fn tracker(&self) -> &T
Returns the resource tracker that will be used for the next snippet.
This is primarily intended for host integrations that need to attach per-execution state, such as cancellation markers, to an existing REPL.
Sourcepub fn tracker_mut(&mut self) -> &mut T
pub fn tracker_mut(&mut self) -> &mut T
Returns mutable access to the resource tracker for the next snippet.
REPL hosts use this to install ephemeral execution controls, such as
async cancellation flags, before calling feed_start().
Sourcepub fn feed_start(
self,
code: &str,
inputs: Vec<(String, MontyObject)>,
print: PrintWriter<'_>,
) -> Result<ReplProgress<T>, Box<ReplStartError<T>>>
pub fn feed_start( self, code: &str, inputs: Vec<(String, MontyObject)>, print: PrintWriter<'_>, ) -> Result<ReplProgress<T>, Box<ReplStartError<T>>>
Starts executing a new snippet and returns suspendable REPL progress.
This is the REPL equivalent of MontyRun::start: execution may complete,
suspend at external calls / OS calls / unresolved futures, or raise a Python
exception. Resume with the returned state object and eventually recover the
updated REPL from ReplProgress::into_complete.
Unlike MontyRepl::feed, this method consumes self so runtime state can be
safely moved into snapshot objects for serialization and cross-process resume.
On a Python-level runtime exception the REPL is not destroyed: it is
returned inside ReplStartError so the caller can continue feeding
subsequent snippets against the same heap and namespace state.
§Errors
Returns Err(Box<ReplStartError>) for syntax, compile-time, or runtime
failures — the REPL session is always preserved inside the error.
Sourcepub fn feed_run(
&mut self,
code: &str,
inputs: Vec<(String, MontyObject)>,
print: PrintWriter<'_>,
) -> Result<MontyObject, MontyException>
pub fn feed_run( &mut self, code: &str, inputs: Vec<(String, MontyObject)>, print: PrintWriter<'_>, ) -> Result<MontyObject, MontyException>
Feeds and executes a new snippet against the current REPL state to completion.
This compiles only code using the existing global slot map, extends the
global namespace if new names are introduced, and executes the snippet once.
Previously executed snippets are never replayed. If execution raises after
partially mutating globals, those mutations remain visible in later feeds,
matching Python REPL semantics.
§Errors
Returns MontyException for syntax/compile/runtime failures.
Sourcepub fn call_function(
&mut self,
name: &str,
args: Vec<MontyObject>,
print: PrintWriter<'_>,
) -> Result<MontyObject, MontyException>
pub fn call_function( &mut self, name: &str, args: Vec<MontyObject>, print: PrintWriter<'_>, ) -> Result<MontyObject, MontyException>
Calls a Python function defined in the session by name.
Looks up the function in the global namespace, converts the arguments, executes the function, and converts the result back.
§Errors
Returns MontyException if the function is not found, not callable,
raises an exception, or encounters an external function call.
Sourcepub fn function_names(&self) -> Vec<&str>
pub fn function_names(&self) -> Vec<&str>
Returns a list of all callable function names defined in the session.
Includes functions, closures, and functions with default arguments. Does not include builtins or external functions.
Sourcepub fn has_function(&self, name: &str) -> bool
pub fn has_function(&self, name: &str) -> bool
Returns whether a function with the given name exists in the session.
Source§impl<T> MontyRepl<T>where
T: ResourceTracker + Serialize,
impl<T> MontyRepl<T>where
T: ResourceTracker + Serialize,
Trait Implementations§
Source§impl<'de, T> Deserialize<'de> for MontyRepl<T>where
T: ResourceTracker + DeserializeOwned,
impl<'de, T> Deserialize<'de> for MontyRepl<T>where
T: ResourceTracker + DeserializeOwned,
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<MontyRepl<T>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<MontyRepl<T>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl<T> Drop for MontyRepl<T>where
T: ResourceTracker,
impl<T> Drop for MontyRepl<T>where
T: ResourceTracker,
Source§impl<T> Serialize for MontyRepl<T>where
T: ResourceTracker + Serialize,
impl<T> Serialize for MontyRepl<T>where
T: ResourceTracker + Serialize,
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl<T> !Freeze for MontyRepl<T>
impl<T> !RefUnwindSafe for MontyRepl<T>
impl<T> !Sync for MontyRepl<T>
impl<T> Send for MontyRepl<T>where
T: Send,
impl<T> Unpin for MontyRepl<T>where
T: Unpin,
impl<T> UnsafeUnpin for MontyRepl<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for MontyRepl<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreimpl<T> MaybeSend for Twhere
T: Send,
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.