Created
April 10, 2019 10:54
-
-
Save antifuchs/00401104d37e4b5b407c2606cdddd243 to your computer and use it in GitHub Desktop.
An example of a failing parse error kind implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
edition = '2018' | |
name = "wtf_nom" | |
version = "0.0.1-dev" | |
authors = ["Andreas Fuchs <[email protected]>"] | |
license = "MIT" | |
[dependencies] | |
nom = "4.2.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use nom::*; | |
#[derive(Debug, PartialEq, Clone)] | |
pub enum ParseErrorKind { | |
Bcrypt, | |
/// An unexpected parse error, indicates a bug in the htpasswd crate | |
Unknown, | |
} | |
impl From<u32> for ParseErrorKind { | |
fn from(f: u32) -> Self { | |
ParseErrorKind::Unknown | |
} | |
} | |
named!(bcrypt_pw<&str, String, ParseErrorKind>, | |
return_error!(ErrorKind::Custom(ParseErrorKind::Bcrypt), | |
do_parse!( | |
peek!(alt_complete!(tag!("$2a$") | tag!("$2y$") | tag!("$2b$"))) >> | |
pw: not_line_ending >> | |
(pw.to_string()) | |
)) | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment