From 0451676ba73f2da76638ae7d0599988c5aed7f53 Mon Sep 17 00:00:00 2001 From: greg Date: Thu, 14 Mar 2019 03:47:56 -0700 Subject: [PATCH] start adding functions to command data structure --- schala-repl/src/repl/command_tree.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/schala-repl/src/repl/command_tree.rs b/schala-repl/src/repl/command_tree.rs index 4ba5167..dcf19ac 100644 --- a/schala-repl/src/repl/command_tree.rs +++ b/schala-repl/src/repl/command_tree.rs @@ -1,16 +1,18 @@ +use super::Repl; + +type BoxedCommandFunction = Box<(fn(&mut Repl, Vec) -> Option)>; #[derive(Clone)] pub enum CommandTree { Terminal { name: String, help_msg: Option, - function: Option Option)>>, + function: Option, }, NonTerminal { name: String, children: Vec, help_msg: Option, - function: Option Option)>>, }, Top(Vec), } @@ -20,12 +22,15 @@ impl CommandTree { CommandTree::Terminal {name: s.to_string(), help_msg: help.map(|x| x.to_string()), function: None } } + pub fn term_with_function(s: &str, help: Option<&str>, func: BoxedCommandFunction) -> CommandTree { + CommandTree::Terminal {name: s.to_string(), help_msg: help.map(|x| x.to_string()), function: Some(func) } + } + pub fn nonterm(s: &str, help: Option<&str>, children: Vec) -> CommandTree { CommandTree::NonTerminal { name: s.to_string(), help_msg: help.map(|x| x.to_string()), children, - function: None, } }