vec_map must be optional

This adds a keys method to the internal implementation of vec_map and
adds conditional compilation in the parser to make the parser compile
with or without the vec_map dependency.
This commit is contained in:
Will Murphy 2018-03-04 15:50:35 -05:00
parent 3401e6a3ec
commit 23a48ea03a
2 changed files with 16 additions and 2 deletions

View file

@ -8,7 +8,7 @@ use std::iter::Peekable;
use std::mem;
// Third party
use vec_map::VecMap;
use map::{self, VecMap};
// Internal
use INTERNAL_ERROR_MSG;
@ -109,6 +109,7 @@ where
}
}
#[cfg_attr(feature = "lints", allow(block_in_if_condition_stmt))]
fn _verify_positionals(&mut self) -> bool {
debugln!("Parser::_verify_positionals;");
@ -118,7 +119,18 @@ where
// Firt we verify that the index highest supplied index, is equal to the number of
// positional arguments to verify there are no gaps (i.e. supplying an index of 1 and 3
// but no 2)
let highest_idx = self.positionals.keys().last().unwrap_or(0);
#[cfg(feature = "vec_map")]
fn _highest_idx(map: &VecMap<&str>) -> usize {
map.keys().last().unwrap_or(0)
}
#[cfg(not(feature = "vec_map"))]
fn _highest_idx(map: &VecMap<&str>) -> usize {
*map.keys().last().unwrap_or(&0)
}
let highest_idx = _highest_idx(&self.positionals);
let num_p = self.positionals.len();
assert!(

View file

@ -32,6 +32,8 @@ mod vec_map {
pub fn values(&self) -> Values<V> { self.inner.values() }
pub fn keys(&self) -> btree_map::Keys<usize, V> { self.inner.keys() }
pub fn iter(&self) -> Iter<V> {
Iter {
inner: self.inner.iter(),