Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created September 18, 2019 22:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/6a0b6b4d35d79c5190b85c43ad6b1e4f to your computer and use it in GitHub Desktop.
Save rust-play/6a0b6b4d35d79c5190b85c43ad6b1e4f to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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