Create a MaterialStorage

[?]
Mar 28, 2021, 11:20 AM
B75B3UUKURXWL6VBIJK3IKNDBH6MOLECYDOZR5LSQQILVMKFMIAAC

Dependencies

  • [2] U4JRHEA7 fmt
  • [3] USO5PZWO Start with the print function, separate mutable and immutable functions
  • [4] VSG6UWDY Can now build floors
  • [5] 5TH3AA46 10 mm extra space
  • [6] 6ODVKCN4 Fix printouts of relative lengths
  • [7] ZJPL7VNQ Separate planks from main

Change contents

  • edit in src/floor.rs at line 5
    [4.77]
    [4.77]
    use crate::AVAILABLEPLANKS;
  • edit in src/floor.rs at line 9
    [4.129]
    [4.129]
    pub struct MaterialStorage {
    total_planks: u32,
    planks_new: Vec<Plank>,
    planks_used: Vec<Plank>,
    planks_too_short: Vec<Plank>,
    }
    impl Default for MaterialStorage {
    /// Create a new, default storage
    fn default() -> Self {
    Self {
    total_planks: AVAILABLEPLANKS,
    planks_new: vec![Plank::default(); AVAILABLEPLANKS as usize],
    planks_used: vec![],
    planks_too_short: vec![],
    }
    }
    }
    impl MaterialStorage {
    pub fn new(&self) -> Self {
    MaterialStorage::default()
    }
    /// Does there exist used/cut planks?
    pub fn exists_used(&self) -> bool {
    !self.planks_used.is_empty()
    }
    /// Get a used plank
    pub fn get_used(&mut self) -> Option<Plank> {
    self.planks_used.pop()
    }
    /// Get how many cut planks exists
    pub fn get_used_count(&self) -> u32 {
    self.planks_used.len() as u32
    }
    /// Does there exist new planks
    pub fn exists_new(&self) -> bool {
    !self.planks_new.is_empty()
    }
    /// Get a new plank
    pub fn get_new(&mut self) -> Option<Plank> {
    self.planks_new.pop()
    }
    }
    // Define a plank piece structure
    #[derive(Debug, Clone, Copy)]
  • replacement in src/floor.rs at line 234
    [3.342][3.342:386]()
    /// Get a mutable reference to the rows
    [3.342]
    [3.386]
    /// Get a reference to the rows
  • edit in src/floor.rs at line 237
    [3.443]
    [3.443]
    }
    /// Get a reference to the previous row
    pub fn last_row(&self) -> Option<&Row> {
    self.rows.last()
  • replacement in src/main.rs at line 4
    [4.3576][2.0:32]()
    use floor::{Floor, Plank, Row};
    [4.3576]
    [4.3608]
    use floor::{Floor, MaterialStorage, Plank, Row};