pub struct NotebookEngine { /* private fields */ }Expand description
Core notebook execution engine
Maintains REPL state across cell executions, enabling variables and state to persist between cells (Jupyter-like behavior).
§Examples
use ruchy::notebook::engine::NotebookEngine;
let mut engine = NotebookEngine::new().unwrap();
let result = engine.execute_cell("let x = 42").unwrap();
assert_eq!(result, "()");
let result = engine.execute_cell("x + 8").unwrap();
assert_eq!(result, "50");Implementations§
Source§impl NotebookEngine
impl NotebookEngine
Sourcepub fn execute_cell(&mut self, code: &str) -> Result<String>
pub fn execute_cell(&mut self, code: &str) -> Result<String>
Execute a cell and return the formatted output
State persists across cell executions (variables remain in scope).
§Errors
Returns error if cell execution fails (parse error, runtime error, etc.)
§Examples
use ruchy::notebook::engine::NotebookEngine;
let mut engine = NotebookEngine::new().unwrap();
let result = engine.execute_cell("1 + 1").unwrap();
assert_eq!(result, "2");Sourcepub fn execute_cell_detailed(&mut self, code: &str) -> CellExecutionResult
pub fn execute_cell_detailed(&mut self, code: &str) -> CellExecutionResult
Execute a cell and return detailed execution results
Returns a CellExecutionResult with output, stdout, stderr, and timing.
§Examples
use ruchy::notebook::engine::NotebookEngine;
let mut engine = NotebookEngine::new().unwrap();
let result = engine.execute_cell_detailed("1 + 1");
assert!(result.is_success());
assert_eq!(result.output(), "2");
assert!(result.duration_ms() < 100);Sourcepub fn create_checkpoint(&self, name: String) -> Checkpoint
pub fn create_checkpoint(&self, name: String) -> Checkpoint
Create a checkpoint of the current notebook state
§Examples
use ruchy::notebook::engine::NotebookEngine;
let mut engine = NotebookEngine::new().unwrap();
engine.execute_cell("let x = 42").unwrap();
let checkpoint = engine.create_checkpoint("before_change".to_string());
assert_eq!(checkpoint.name(), "before_change");Sourcepub fn restore_checkpoint(&mut self, checkpoint: &Checkpoint)
pub fn restore_checkpoint(&mut self, checkpoint: &Checkpoint)
Restore notebook state from a checkpoint
§Examples
use ruchy::notebook::engine::NotebookEngine;
let mut engine = NotebookEngine::new().unwrap();
engine.execute_cell("let x = 10").unwrap();
let checkpoint = engine.create_checkpoint("save".to_string());
engine.execute_cell("x = 99").unwrap();
engine.restore_checkpoint(&checkpoint);
let result = engine.execute_cell("x").unwrap();
assert_eq!(result, "10");Sourcepub fn execute_transaction(&mut self, code: &str) -> TransactionResult<String>
pub fn execute_transaction(&mut self, code: &str) -> TransactionResult<String>
Execute code transactionally with automatic rollback on error
If execution fails, state is automatically rolled back to before the transaction.
§Examples
use ruchy::notebook::engine::NotebookEngine;
let mut engine = NotebookEngine::new().unwrap();
engine.execute_cell("let x = 10").unwrap();
// This will fail and rollback
let result = engine.execute_transaction("x = invalid_syntax");
assert!(result.is_rolled_back());
// Original state preserved
let value = engine.execute_cell("x").unwrap();
assert_eq!(value, "10");Trait Implementations§
Auto Trait Implementations§
impl Freeze for NotebookEngine
impl !RefUnwindSafe for NotebookEngine
impl !Send for NotebookEngine
impl !Sync for NotebookEngine
impl Unpin for NotebookEngine
impl !UnwindSafe for NotebookEngine
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
Mutably borrows from an owned value. Read more
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>
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 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>
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