pub struct Repl<'a, T> {
pub data: T,
/* private fields */
}Expand description
Main Repl Struct that contains all logic for the crate
Fields§
§data: Tstruct to store data, used as an argument in all functions
Implementations§
Source§impl<'a, T> Repl<'a, T>
impl<'a, T> Repl<'a, T>
Sourcepub fn new(data: T) -> Self
pub fn new(data: T) -> Self
builds a new Repl from the given data
§Examples
use repl_framework::Repl;
let repl: Repl<()> = Repl::new(());Sourcepub fn run(&mut self) -> Result<()>
pub fn run(&mut self) -> Result<()>
runs the repl
functions which have command "" will be called if none of the other commands are not called.
§Examples
use repl_framework::Repl;
Repl::default().with_function("", |_: &mut (), b| println!("{:?}", b)).run();§Errors
- reading from stdin fails
- flushing stdout fails
Examples found in repository?
More examples
Sourcepub fn new_with_depreciated_parser(data: T) -> Self
pub fn new_with_depreciated_parser(data: T) -> Self
builds a new Repl from the given data, use for compatibility reasons only, the new parser is better in pretty much every way possible
§Examples
use repl_framework::Repl;
let repl: Repl<()> = Repl::new_with_depreciated_parser(());Sourcepub fn get_input(&self) -> Result<Vec<String>>
pub fn get_input(&self) -> Result<Vec<String>>
same as take_arg, but returns the argument instead of storing it in self.argument
§Errors
this function returns an error if
- reading from stdin fails
- flushing stdout fails
Sourcepub fn with_function(self, name: &'a str, func: fn(&mut T, Vec<String>)) -> Self
pub fn with_function(self, name: &'a str, func: fn(&mut T, Vec<String>)) -> Self
builder style method for adding a function.
this function is chainable, use add_function if you don’t want it to be chainable.
§Example
use repl_framework::Repl;
let repl: Repl<()> = Repl::default().with_function("hello", hello);
fn hello(_: &mut (), _: Vec<String>) {
println!("hello");
}Examples found in repository?
More examples
Sourcepub fn with_parser(self, parser: fn(String) -> Vec<String>) -> Self
pub fn with_parser(self, parser: fn(String) -> Vec<String>) -> Self
builder style method for changing the parser.
this function is chainable, use set_parser if you don’t want it to be chainable.
§Examples
use repl_framework::Repl;
let repl: Repl<()> = Repl::default().with_parser(|raw| vec![raw]);Sourcepub fn with_data(self, data: T) -> Self
pub fn with_data(self, data: T) -> Self
builder style method for changing the data.
this function is chainable, use set_data if you don’t want it to be chainable.
§Examples
use repl_framework::Repl;
let repl: Repl<()> = Repl::default().with_data(());Sourcepub fn with_prompt(self, prompt: &'a str) -> Self
pub fn with_prompt(self, prompt: &'a str) -> Self
builder style method for changing the prompt.
this function is chainable, use set_prompt if you don’t want it to be chainable.
§Examples
use repl_framework::Repl;
let repl: Repl<()> = Repl::default().with_prompt("+>");
// the repl will display +> after every message now, instead of the default ">>>"Examples found in repository?
More examples
Sourcepub fn with_exit_command(self, exit: &'a str) -> Self
pub fn with_exit_command(self, exit: &'a str) -> Self
builder style method for changing the exit command.
this function is chainable, use set_exit_command if you don’t want it to be chainable.
§Examples
use repl_framework::Repl;
let repl: Repl<()> = Repl::default().with_exit_command("close");
// the repl will close if you give "close" as input nowSourcepub fn with_exit_message(self, exit_message: &'a str) -> Self
pub fn with_exit_message(self, exit_message: &'a str) -> Self
builder style method for changing the exit message.
this function is chainable, use set_exit_message if you don’t want it to be chainable.
§Examples
use repl_framework::Repl;
let repl: Repl<()> = Repl::default().with_exit_message("repl closed!");
// the repl will display "repl closed!" on terminationSourcepub fn with_empty_argument_message(
self,
empty_argument_message: &'a str,
) -> Self
pub fn with_empty_argument_message( self, empty_argument_message: &'a str, ) -> Self
builder style method for changing the exit message.
this function is chainable, use set_exit_message if you don’t want it to be chainable.
§Examples
use repl_framework::Repl;
let repl: Repl<()> = Repl::default().with_empty_argument_message("empty arg :(");
// the repl will display "empty arg :(" on terminationSourcepub fn add_function(&mut self, name: &'a str, func: fn(&mut T, Vec<String>))
pub fn add_function(&mut self, name: &'a str, func: fn(&mut T, Vec<String>))
adds function to Repl, not chainable, use with_function if you want chaining
§Examples
use repl_framework::Repl;
let mut repl: Repl<()> = Repl::default();
repl.add_function("hello", hello);
fn hello(_: &mut (), _: Vec<String>) {
println!("Hello!")
}Sourcepub fn set_data(&mut self, data: T)
pub fn set_data(&mut self, data: T)
sets data to argument, NOT chainable, use with_data if you want chaining.
§Examples
use repl_framework::Repl;
let mut repl: Repl<i32> = Repl::default();
repl.set_data(100);Sourcepub fn set_prompt(&mut self, prompt: &'a str)
pub fn set_prompt(&mut self, prompt: &'a str)
sets prompt to argument, NOT chainable, use with_prompt if you want chaining.
§Examples
use repl_framework::Repl;
let mut repl: Repl<()> = Repl::default();
repl.set_prompt(":>");
Sourcepub fn set_exit_command(&mut self, exit: &'a str)
pub fn set_exit_command(&mut self, exit: &'a str)
sets exit command to argument, NOT chainable, use with_exit_command if you want chaining.
§Examples
use repl_framework::Repl;
let mut repl: Repl<()> = Repl::default();
repl.set_exit_command("close!");Sourcepub fn set_exit_message(&mut self, exit_message: &'a str)
pub fn set_exit_message(&mut self, exit_message: &'a str)
sets exit message to argument, NOT chainable, use with_exit_message if you want chaining.
§Examples
use repl_framework::Repl;
let mut repl: Repl<()> = Repl::default();
repl.set_exit_message("bye!");Sourcepub fn set_empty_argument_message(&mut self, empty_argument_message: &'a str)
pub fn set_empty_argument_message(&mut self, empty_argument_message: &'a str)
sets exit message to argument, NOT chainable, use with_exit_message if you want chaining.
§Examples
use repl_framework::Repl;
let mut repl: Repl<()> = Repl::default();
repl.set_empty_argument_message("empty argument list!");