rust/vec2d/src/lib.rs
changeset 13915 f64790b2a725
parent 13911 fa9f93393e9c
child 13916 cd437d76978a
equal deleted inserted replaced
13914:ef50e4f59b8f 13915:f64790b2a725
    31     }
    31     }
    32 }
    32 }
    33 
    33 
    34 impl<T: Copy> Vec2D<T> {
    34 impl<T: Copy> Vec2D<T> {
    35     pub fn new(width: usize, height: usize, value: T) -> Self {
    35     pub fn new(width: usize, height: usize, value: T) -> Self {
    36         let mut vec = Self {
    36         Self {
    37             data: Vec::new(),
    37             data: vec![value; width * height],
    38             width,
    38             width,
    39             height,
    39             height,
    40         };
    40         }
    41 
       
    42         vec.data.extend(iter::repeat(value).take(width * height));
       
    43 
       
    44         vec
       
    45     }
    41     }
    46 
    42 
    47     #[inline]
    43     #[inline]
    48     pub fn width(&self) -> usize {
    44     pub fn width(&self) -> usize {
    49         self.width
    45         self.width