From 11571df5739a103914883e6e6ae8100720a96187 Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Sun, 30 Aug 2020 14:20:30 +0200 Subject: [PATCH] update the docs on char --- src/character/complete.rs | 11 +++++++---- src/character/streaming.rs | 11 +++++++---- src/error.rs | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/character/complete.rs b/src/character/complete.rs index 39e529d..708846d 100644 --- a/src/character/complete.rs +++ b/src/character/complete.rs @@ -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>(c: char) -> impl Fn(I) -> IResult diff --git a/src/character/streaming.rs b/src/character/streaming.rs index 0b36ad7..5e10929 100644 --- a/src/character/streaming.rs +++ b/src/character/streaming.rs @@ -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>(c: char) -> impl Fn(I) -> IResult diff --git a/src/error.rs b/src/error.rs index ba8151a..dc51a83 100644 --- a/src/error.rs +++ b/src/error.rs @@ -110,7 +110,7 @@ impl ParseError for (I, ErrorKind) { impl ContextError for (I, ErrorKind) {} impl FromExternalError 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) } }