From 6af10ba53dc8bb990a0b410e00e6398b754ae2eb Mon Sep 17 00:00:00 2001 From: shimun Date: Sun, 10 Nov 2019 21:38:10 +0100 Subject: [PATCH] use iter to init board --- src/main.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index b812dcf..16258c7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ use std::env::args; use std::fmt; use std::io; use std::io::Write; +use std::iter; use std::ops::{Index, IndexMut}; use std::str::FromStr; @@ -92,11 +93,7 @@ impl FromStr for Board { impl Board { fn new(size: usize) -> Board { - let mut b = Vec::with_capacity(size * size); - for _ in 0..b.capacity() { - b.push(State::N); - } - Board(b) + Board(iter::repeat(State::N).take(size * size).collect()) } fn dimension(&self) -> usize {