Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created October 18, 2019 02:30
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/92b3606aa84e0b49b2e6165999e088b4 to your computer and use it in GitHub Desktop.
Save rust-play/92b3606aa84e0b49b2e6165999e088b4 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
fn main(){
let spots = make_board();
render(&spots)
}
fn make_board() -> Vec<Tokens> {
let mut count = 0;
let mut spots:Vec<Tokens> = Vec::new();
let values = [4,9,2,3,5,7,8,1,6];
for val in &values {
let tok = Tokens::new(count, *val, ' ');
spots.push(tok);
}
spots
}
fn render(spots: &Vec<Tokens>) {
println!(" | | ");
println!(" {} | {} | {} ", spots[0].chr, spots[1].chr, spots[2].chr);
println!(" | | ");
println!(" | | ");
println!(" {} | {} | {} ", spots[3].chr, spots[4].chr, spots[5].chr);
println!(" | | ");
println!(" | | ");
println!(" {} | {} | {} ", spots[6].chr, spots[7].chr, spots[8].chr);
println!(" | | ");
}
struct Tokens{
idx:i8,
val:i8,
chr:char,
}
impl Tokens{
fn new(idx: i8, val: i8, chr: char) -> Tokens {
Tokens { idx: idx, val: val, chr: chr}
}
fn update(&mut self, chr: &char) {
self.chr = chr;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment