mirror of
https://gitee.com/openharmony/third_party_rust_nom
synced 2024-11-23 07:29:54 +00:00
Implement nom::sequence::Tuple
for ()
(Unit)
This commit is contained in:
parent
1a686f5180
commit
761ab0a24f
@ -252,6 +252,15 @@ macro_rules! tuple_trait_inner(
|
||||
tuple_trait!(FnA A, FnB B, FnC C, FnD D, FnE E, FnF F, FnG G, FnH H, FnI I, FnJ J, FnK K, FnL L,
|
||||
FnM M, FnN N, FnO O, FnP P, FnQ Q, FnR R, FnS S, FnT T, FnU U);
|
||||
|
||||
// Special case: implement `Tuple` for `()`, the unit type.
|
||||
// This can come up in macros which accept a variable number of arguments.
|
||||
// Literally, `()` is an empty tuple, so it should simply parse nothing.
|
||||
impl<I, E: ParseError<I>> Tuple<I, (), E> for () {
|
||||
fn parse(&mut self, input: I) -> IResult<I, (), E> {
|
||||
Ok((input, ()))
|
||||
}
|
||||
}
|
||||
|
||||
///Applies a tuple of parsers one by one and returns their results as a tuple.
|
||||
///There is a maximum of 21 parsers
|
||||
/// ```rust
|
||||
|
@ -1,6 +1,6 @@
|
||||
use super::*;
|
||||
use crate::bytes::streaming::{tag, take};
|
||||
use crate::error::ErrorKind;
|
||||
use crate::error::{ErrorKind, Error};
|
||||
use crate::internal::{Err, IResult, Needed};
|
||||
use crate::number::streaming::be_u16;
|
||||
|
||||
@ -272,3 +272,10 @@ fn tuple_test() {
|
||||
Err(Err::Error(error_position!(&b"jk"[..], ErrorKind::Tag)))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unit_type() {
|
||||
assert_eq!(tuple::<&'static str, (), Error<&'static str>, ()>(())("abxsbsh"), Ok(("abxsbsh", ())));
|
||||
assert_eq!(tuple::<&'static str, (), Error<&'static str>, ()>(())("sdfjakdsas"), Ok(("sdfjakdsas", ())));
|
||||
assert_eq!(tuple::<&'static str, (), Error<&'static str>, ()>(())(""), Ok(("", ())));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user