mirror of
https://gitee.com/openharmony/third_party_rust_nom
synced 2024-11-23 15:40:19 +00:00
update the docs on char
This commit is contained in:
parent
3dcddc9cc1
commit
11571df573
@ -15,12 +15,15 @@ use crate::traits::{Compare, CompareResult};
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// # use nom::{Err, error::ErrorKind};
|
||||
/// # use nom::{Err, error::{ErrorKind, Error}, IResult};
|
||||
/// # use nom::character::complete::char;
|
||||
/// # fn main() {
|
||||
/// assert_eq!(char::<_, (&str, ErrorKind)>('a')("abc"), Ok(("bc", 'a')));
|
||||
/// assert_eq!(char::<_, (&str, ErrorKind)>('a')("bc"), Err(Err::Error(("bc", ErrorKind::Char))));
|
||||
/// assert_eq!(char::<_, (&str, ErrorKind)>('a')(""), Err(Err::Error(("", ErrorKind::Char))));
|
||||
/// fn parser(i: &str) -> IResult<&str, char> {
|
||||
/// char('a')(i)
|
||||
/// }
|
||||
/// assert_eq!(parser("abc"), Ok(("bc", 'a')));
|
||||
/// assert_eq!(parser("bc"), Err(Err::Error(Error::new("bc", ErrorKind::Char))));
|
||||
/// assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::Char))));
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn char<I, Error: ParseError<I>>(c: char) -> impl Fn(I) -> IResult<I, char, Error>
|
||||
|
@ -16,12 +16,15 @@ use crate::error::ErrorKind;
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// # use nom::{Err, error::ErrorKind, Needed};
|
||||
/// # use nom::{Err, error::{ErrorKind, Error}, Needed, IResult};
|
||||
/// # use nom::character::streaming::char;
|
||||
/// # fn main() {
|
||||
/// assert_eq!(char::<_, (_, ErrorKind)>('a')(&b"abc"[..]), Ok((&b"bc"[..], 'a')));
|
||||
/// assert_eq!(char::<_, (_, ErrorKind)>('a')(&b"bc"[..]), Err(Err::Error((&b"bc"[..], ErrorKind::Char))));
|
||||
/// assert_eq!(char::<_, (_, ErrorKind)>('a')(&b""[..]), Err(Err::Incomplete(Needed::new(1))));
|
||||
/// fn parser(i: &str) -> IResult<&str, char> {
|
||||
/// char('a')(i)
|
||||
/// }
|
||||
/// assert_eq!(parser("abc"), Ok(("bc", 'a')));
|
||||
/// assert_eq!(parser("bc"), Err(Err::Error(Error::new("bc", ErrorKind::Char))));
|
||||
/// assert_eq!(parser(""), Err(Err::Incomplete(Needed::new(1))));
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn char<I, Error: ParseError<I>>(c: char) -> impl Fn(I) -> IResult<I, char, Error>
|
||||
|
@ -110,7 +110,7 @@ impl<I> ParseError<I> for (I, ErrorKind) {
|
||||
impl<I> ContextError<I> for (I, ErrorKind) {}
|
||||
|
||||
impl<I, E> FromExternalError<I, E> for (I, ErrorKind) {
|
||||
fn from_external_error(input: I, kind: ErrorKind, e: E) -> Self {
|
||||
fn from_external_error(input: I, kind: ErrorKind, _e: E) -> Self {
|
||||
(input, kind)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user