Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created September 12, 2020 02:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/6f58c354416c0c771c344c7b0c10b4a1 to your computer and use it in GitHub Desktop.
Save rust-play/6f58c354416c0c771c344c7b0c10b4a1 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
struct Foo<'a> {
tokens:Vec<i32>,
current_tok:Option<&'a i32>,
}
impl<'a> Foo<'a> {
fn new(tokens:Vec<i32>) -> Foo<'a> {
Foo {
tokens,
current_tok: None,
}
}
}
fn main() {
let mut foo = Foo::new(vec![1,2,5]);
foo.current_tok = foo.tokens.first();
match foo.tokens.first() {
Some(x) => println!("{}",x),
_ => {},
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment