Skip to content

Commit 61c3568

Browse files
committed
Revert "Reverting type parameter to T"
This reverts commit 15bb5a5.
1 parent 26ad7fa commit 61c3568

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

src/lib.rs

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
pub mod menu_manager;
88

99
/// The type of function we call when we enter/exit a menu.
10-
pub type MenuCallbackFn<T> = fn(menu: &Menu<T>, context: &mut T);
10+
pub type MenuCallbackFn<C> = fn(menu: &Menu<C>, context: &mut C);
1111

1212
/// The type of function we call when we a valid command has been entered.
13-
pub type ItemCallbackFn<T> = fn(menu: &Menu<T>, item: &Item<T>, args: &[&str], context: &mut T);
13+
pub type ItemCallbackFn<C> = fn(menu: &Menu<C>, item: &Item<C>, args: &[&str], context: &mut C);
1414

1515
#[derive(Debug)]
1616
/// Describes a parameter to the command
@@ -49,65 +49,65 @@ pub enum Parameter<'a> {
4949

5050
/// Do we enter a sub-menu when this command is entered, or call a specific
5151
/// function?
52-
pub enum ItemType<'a, T>
52+
pub enum ItemType<'a, C>
5353
where
54-
T: 'a,
54+
C: 'a,
5555
{
5656
/// Call a function when this command is entered
5757
Callback {
5858
/// The function to call
59-
function: ItemCallbackFn<T>,
59+
function: ItemCallbackFn<C>,
6060
/// The list of parameters for this function. Pass an empty list if there aren't any.
6161
parameters: &'a [Parameter<'a>],
6262
},
6363
/// This item is a sub-menu you can enter
64-
Menu(&'a Menu<'a, T>),
64+
Menu(&'a Menu<'a, C>),
6565
/// Internal use only - do not use
6666
_Dummy,
6767
}
6868

6969
/// An `Item` is a what our menus are made from. Each item has a `name` which
7070
/// you have to enter to select this item. Each item can also have zero or
7171
/// more parameters, and some optional help text.
72-
pub struct Item<'a, T>
72+
pub struct Item<'a, C>
7373
where
74-
T: 'a,
74+
C: 'a,
7575
{
7676
/// The word you need to enter to activate this item. It is recommended
7777
/// that you avoid whitespace in this string.
7878
pub command: &'a str,
7979
/// Optional help text. Printed if you enter `help`.
8080
pub help: Option<&'a str>,
8181
/// The type of this item - menu, callback, etc.
82-
pub item_type: ItemType<'a, T>,
82+
pub item_type: ItemType<'a, C>,
8383
}
8484

8585
/// A `Menu` is made of one or more `Item`s.
86-
pub struct Menu<'a, T>
86+
pub struct Menu<'a, C>
8787
where
88-
T: 'a,
88+
C: 'a,
8989
{
9090
/// Each menu has a label which is visible in the prompt, unless you are
9191
/// the root menu.
9292
pub label: &'a str,
9393
/// A slice of menu items in this menu.
94-
pub items: &'a [&'a Item<'a, T>],
94+
pub items: &'a [&'a Item<'a, C>],
9595
/// A function to call when this menu is entered. If this is the root menu, this is called when the runner is created.
96-
pub entry: Option<MenuCallbackFn<T>>,
96+
pub entry: Option<MenuCallbackFn<C>>,
9797
/// A function to call when this menu is exited. Never called for the root menu.
98-
pub exit: Option<MenuCallbackFn<T>>,
98+
pub exit: Option<MenuCallbackFn<C>>,
9999
}
100100

101101
/// This structure handles the menu. You feed it bytes as they are read from
102102
/// the console and it executes menu actions when commands are typed in
103103
/// (followed by Enter).
104-
pub struct Runner<'a, T>
104+
pub struct Runner<'a, C>
105105
where
106-
T: embedded_io::Write + embedded_io::Read + embedded_io::ReadReady,
106+
C: embedded_io::Write + embedded_io::Read + embedded_io::ReadReady,
107107
{
108108
buffer: &'a mut [u8],
109109
used: usize,
110-
menu_mgr: menu_manager::MenuManager<'a, T>,
110+
menu_mgr: menu_manager::MenuManager<'a, C>,
111111
}
112112

113113
/// Describes the ways in which the API can fail
@@ -129,8 +129,8 @@ pub enum Error {
129129
/// (and hence doesn't take a value).
130130
/// * Returns `Err(())` if `parameter_name` was not in `item.parameter_list`
131131
/// or `item` wasn't an Item::Callback
132-
pub fn argument_finder<'a, T>(
133-
item: &'a Item<'a, T>,
132+
pub fn argument_finder<'a, C>(
133+
item: &'a Item<'a, C>,
134134
argument_list: &'a [&'a str],
135135
name_to_find: &'a str,
136136
) -> Result<Option<&'a str>, Error> {
@@ -234,8 +234,8 @@ enum Outcome {
234234
NeedMore,
235235
}
236236

237-
impl<'a, T> core::clone::Clone for Menu<'a, T> {
238-
fn clone(&self) -> Menu<'a, T> {
237+
impl<'a, C> core::clone::Clone for Menu<'a, C> {
238+
fn clone(&self) -> Menu<'a, C> {
239239
Menu {
240240
label: self.label,
241241
items: self.items,
@@ -245,15 +245,15 @@ impl<'a, T> core::clone::Clone for Menu<'a, T> {
245245
}
246246
}
247247

248-
impl<'a, T> Runner<'a, T>
248+
impl<'a, C> Runner<'a, C>
249249
where
250-
T: embedded_io::Write + embedded_io::Read + embedded_io::ReadReady,
250+
C: embedded_io::Write + embedded_io::Read + embedded_io::ReadReady,
251251
{
252252
/// Create a new `Runner`. You need to supply a top-level menu, and a
253253
/// buffer that the `Runner` can use. Feel free to pass anything as the
254254
/// `context` type - the only requirement is that the `Runner` can
255255
/// `write!` to the context, which it will do for all text output.
256-
pub fn new(menu: Menu<'a, T>, buffer: &'a mut [u8], context: &mut T) -> Self {
256+
pub fn new(menu: Menu<'a, C>, buffer: &'a mut [u8], context: &mut C) -> Self {
257257
if let Some(cb_fn) = menu.entry {
258258
cb_fn(&menu, context);
259259
}
@@ -268,7 +268,7 @@ where
268268

269269
/// Print out a new command prompt, including sub-menu names if
270270
/// applicable.
271-
pub fn prompt(&mut self, newline: bool, context: &mut T) {
271+
pub fn prompt(&mut self, newline: bool, context: &mut C) {
272272
if newline {
273273
writeln!(context).unwrap();
274274
}
@@ -286,7 +286,7 @@ where
286286
/// Process input data for command lines.
287287
///
288288
/// By default, an echo feature is enabled to display commands on the terminal.
289-
pub fn process(&mut self, context: &mut T) {
289+
pub fn process(&mut self, context: &mut C) {
290290
while context.read_ready().unwrap() {
291291
let mut input_buf = [0; 1];
292292
context.read(&mut input_buf).unwrap();
@@ -354,7 +354,7 @@ where
354354
}
355355

356356
/// Scan the buffer and do the right thing based on its contents.
357-
fn process_command(&mut self, context: &mut T) {
357+
fn process_command(&mut self, context: &mut C) {
358358
// Go to the next line, below the prompt
359359
writeln!(context).unwrap();
360360
if let Ok(command_line) = core::str::from_utf8(&self.buffer[0..self.used]) {
@@ -447,7 +447,7 @@ where
447447
}
448448
}
449449

450-
fn print_short_help(&mut self, context: &mut T, item: &Item<T>) {
450+
fn print_short_help(&mut self, context: &mut C, item: &Item<C>) {
451451
let mut has_options = false;
452452
match item.item_type {
453453
ItemType::Callback { parameters, .. } => {
@@ -484,7 +484,7 @@ where
484484
writeln!(context).unwrap();
485485
}
486486

487-
fn print_long_help(&mut self, context: &mut T, item: &Item<T>) {
487+
fn print_long_help(&mut self, context: &mut C, item: &Item<C>) {
488488
writeln!(context, "SUMMARY:").unwrap();
489489
match item.item_type {
490490
ItemType::Callback { parameters, .. } => {
@@ -582,11 +582,11 @@ where
582582
}
583583

584584
fn call_function(
585-
context: &mut T,
586-
callback_function: ItemCallbackFn<T>,
585+
context: &mut C,
586+
callback_function: ItemCallbackFn<C>,
587587
parameters: &[Parameter],
588-
parent_menu: &Menu<T>,
589-
item: &Item<T>,
588+
parent_menu: &Menu<C>,
589+
item: &Item<C>,
590590
command: &str,
591591
) {
592592
let mandatory_parameter_count = parameters

0 commit comments

Comments
 (0)