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 38)
27fn converse(args: &[&str], _context: &mut DynamicContext)->Result<String, Box<dyn Error>>{
28 if args.len() == 0 {
29 return Ok("no name provided".to_string());
30 }
31 println!("interacting with: {}", args[0]);
32 let commands = vec![
33 Command{command: "hello", func: hello, help_output: "hello - say hello"},
34 Command{command: "change", func: change, help_output: "change <name> - change the name of the person with whom you're speaking"},
35 ];
36
37 // let mut name: Option<Box<dyn Any>> = Some(Box::new(args[0].to_string()));
38 let mut context = DynamicContext::new();
39 context.set("name",args[0].to_string());
40 // passing the arguments for the converse commands as context
41 // to the commands in the next command loop for reference
42 if let Err(e) = command_loop(&commands, &mut context){
43 eprintln!("error running interact command loop: {}", e);
44 }
45 Ok(String::new())
46}
47
48fn main(){
49 let commands = vec![
50 Command{
51 command: "converse",
52 func: converse,
53 help_output: "converse <name> - interact with a person"
54 },
55 ];
56
57 // start the command loop with the provided commands
58 if let Err(e) = command_loop(&commands, &mut DynamicContext::new()){
59 eprintln!("error running command loop: {}", e.to_string());
60 }
61}Sourcepub fn set<T: 'static>(&mut self, key: &str, value: T)
pub fn set<T: 'static>(&mut self, key: &str, value: T)
Examples found in repository?
examples/conversation.rs (line 39)
27fn converse(args: &[&str], _context: &mut DynamicContext)->Result<String, Box<dyn Error>>{
28 if args.len() == 0 {
29 return Ok("no name provided".to_string());
30 }
31 println!("interacting with: {}", args[0]);
32 let commands = vec![
33 Command{command: "hello", func: hello, help_output: "hello - say hello"},
34 Command{command: "change", func: change, help_output: "change <name> - change the name of the person with whom you're speaking"},
35 ];
36
37 // let mut name: Option<Box<dyn Any>> = Some(Box::new(args[0].to_string()));
38 let mut context = DynamicContext::new();
39 context.set("name",args[0].to_string());
40 // passing the arguments for the converse commands as context
41 // to the commands in the next command loop for reference
42 if let Err(e) = command_loop(&commands, &mut context){
43 eprintln!("error running interact command loop: {}", e);
44 }
45 Ok(String::new())
46}Auto Trait Implementations§
impl Freeze for DynamicContext
impl !RefUnwindSafe for DynamicContext
impl !Send for DynamicContext
impl !Sync for DynamicContext
impl Unpin for DynamicContext
impl UnsafeUnpin 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