Struct console_prompt::DynamicContext
source · pub struct DynamicContext { /* private fields */ }Implementations§
source§impl DynamicContext
impl DynamicContext
sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/conversation.rs (line 50)
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
fn converse(args: &[&str], _context: &mut DynamicContext)->Result<String, Box<dyn Error>>{
if args.len() == 0 {
return Ok("no name provided".to_string());
}
println!("interacting with: {}", args[0]);
let commands = vec![
Command{command: "hello", func: hello, help_output: "hello - say hello"},
Command{command: "change", func: change, help_output: "change <name> - change the name of the person with whom you're speaking"},
//Command{command: "yes", func: yes, help_output: "yes - reply yes"},
//Command{command: "no", func: no, help_output: "no - reply no"},
];
// let mut name: Option<Box<dyn Any>> = Some(Box::new(args[0].to_string()));
let mut context = DynamicContext::new();
context.set(args[0].to_string());
// passing the arguments for the converse commands as context
// to the commands in the next command loop for reference
if let Err(e) = command_loop(&commands, &mut context){
eprintln!("error running interact command loop: {}", e);
}
Ok(String::new())
}
fn main(){
let commands = vec![
Command{
command: "converse",
func: converse,
help_output: "converse <name> - interact with a person"
},
];
// start the command loop with the provided commands
if let Err(e) = command_loop(&commands, &mut DynamicContext::new()){
eprintln!("error running command loop: {}", e.to_string());
}
}sourcepub fn set<T: 'static>(&mut self, value: T)
pub fn set<T: 'static>(&mut self, value: T)
Examples found in repository?
examples/conversation.rs (line 51)
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
fn converse(args: &[&str], _context: &mut DynamicContext)->Result<String, Box<dyn Error>>{
if args.len() == 0 {
return Ok("no name provided".to_string());
}
println!("interacting with: {}", args[0]);
let commands = vec![
Command{command: "hello", func: hello, help_output: "hello - say hello"},
Command{command: "change", func: change, help_output: "change <name> - change the name of the person with whom you're speaking"},
//Command{command: "yes", func: yes, help_output: "yes - reply yes"},
//Command{command: "no", func: no, help_output: "no - reply no"},
];
// let mut name: Option<Box<dyn Any>> = Some(Box::new(args[0].to_string()));
let mut context = DynamicContext::new();
context.set(args[0].to_string());
// passing the arguments for the converse commands as context
// to the commands in the next command loop for reference
if let Err(e) = command_loop(&commands, &mut context){
eprintln!("error running interact command loop: {}", e);
}
Ok(String::new())
}Auto Trait Implementations§
impl !RefUnwindSafe for DynamicContext
impl !Send for DynamicContext
impl !Sync for DynamicContext
impl Unpin for DynamicContext
impl !UnwindSafe for DynamicContext
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