-
-
Save rust-play/d37fd14287397b722dcf8515d86542a1 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 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: tokens.first(), | |
} | |
} | |
} | |
fn main() { | |
let foo = Foo::new(vec![1,2,5]); | |
// Not assigning here >>> | |
// 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