pub struct ReplInterface { /* private fields */ }Expand description
REPL (Read-Eval-Print Loop) interface
Provides an interactive command-line interface with:
- Line editing and history
- Persistent command history
- Graceful error handling
- Special commands (exit, quit, help)
§Architecture
User input → rustyline → ReplParser → CommandExecutor → Handler
↓
ExecutionContext§Special Commands
The REPL recognizes these built-in commands:
exit,quit- Exit the REPLhelp- Show available commands (if registered)
§History
Command history is stored in the user’s config directory:
- Linux:
~/.config/<app_name>/history.txt - macOS:
~/Library/Application Support/<app_name>/history.txt - Windows:
%APPDATA%\<app_name>\history.txt
Implementations§
Source§impl ReplInterface
impl ReplInterface
Sourcepub fn new(
registry: CommandRegistry,
context: Box<dyn ExecutionContext>,
prompt: String,
) -> Result<Self>
pub fn new( registry: CommandRegistry, context: Box<dyn ExecutionContext>, prompt: String, ) -> Result<Self>
Create a new REPL interface
§Arguments
registry- Command registry with all registered commandscontext- Execution contextprompt- Prompt prefix (e.g., “myapp” will display as “myapp > “)
§Errors
Returns an error if rustyline initialization fails (rare).
§Example
use dynamic_cli::interface::ReplInterface;
use dynamic_cli::prelude::*;
let registry = CommandRegistry::new();
let context = Box::new(MyContext::default());
let repl = ReplInterface::new(registry, context, "myapp".to_string())?;Sourcepub fn run(self) -> Result<()>
pub fn run(self) -> Result<()>
Run the REPL loop
Enters an interactive loop that:
- Displays the prompt
- Reads user input
- Parses and executes the command
- Displays results or errors
- Repeats until user exits
§Returns
Ok(())when user exits normally (viaexitorquit)Err(_)on critical errors (I/O failures, etc.)
§Example
use dynamic_cli::interface::ReplInterface;
use dynamic_cli::prelude::*;
let registry = CommandRegistry::new();
let context = Box::new(MyContext::default());
let repl = ReplInterface::new(registry, context, "myapp".to_string())?;
repl.run()?; // Starts the REPL loopTrait Implementations§
Auto Trait Implementations§
impl Freeze for ReplInterface
impl !RefUnwindSafe for ReplInterface
impl Send for ReplInterface
impl Sync for ReplInterface
impl Unpin for ReplInterface
impl !UnwindSafe for ReplInterface
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