diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f3be5c..a367bc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Adds method `into_buf` for `Box` and `impl From for Box`. - Adds unsafe associated methods `Pointer::new_unchecked` and `PointerBuf::new_unchecked` for external zero-cost construction. +- Adds `Token::is_next` for checking if a token represents the `-` character. ### Changed diff --git a/src/token.rs b/src/token.rs index 1b70955..0447d20 100644 --- a/src/token.rs +++ b/src/token.rs @@ -251,6 +251,13 @@ impl<'a> Token<'a> { pub fn to_index(&self) -> Result { self.try_into() } + + /// Returns if the `Token` is `-`, which stands for the next array index. + /// + /// See also [`Self::to_index`]. + pub fn is_next(&self) -> bool { + matches!(self.to_index(), Ok(Index::Next)) + } } macro_rules! impl_from_num { @@ -491,4 +498,16 @@ mod tests { ] }); } + + #[test] + fn is_next() { + let token = Token::new("-"); + assert!(token.is_next()); + let token = Token::new("0"); + assert!(!token.is_next()); + let token = Token::new("a"); + assert!(!token.is_next()); + let token = Token::new(""); + assert!(!token.is_next()); + } }