Created
September 18, 2019 22:23
-
-
Save rust-play/6a0b6b4d35d79c5190b85c43ad6b1e4f to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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
struct Context<'s>(&'s str); | |
struct Parser<'a, 's>{ | |
context: &'a Context<'s>, | |
} | |
impl<'a, 's> Parser<'a, 's> { | |
fn new(context: &'a Context<'s>)->Parser<'a, 's>{ | |
Parser{context} | |
} | |
fn parse(&'a self) -> Result<(), &'s str> { | |
Err(&self.context.0[1..]) | |
} | |
} | |
fn parse_context<'a>(context: Context<'a>) -> Result<(), &'a str> { | |
Parser::new(&context).parse() | |
} | |
fn main() { | |
let c = Context("Hello"); | |
if let Err(r) = parse_context(c) { | |
println!("{}", r); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment