impl Default for Plank {
/// Create a new, default plank
fn default() -> Self {
Self {
length: PLANKMAX,
endpiece: false,
new: true,
}
}
}
impl Plank {
/// Is this row considered complete?
fn is_new(&self) -> bool {
self.new
}
/// Get the number of plank rows for this floor
fn is_endpiece(&self) -> bool {
self.endpiece
}
fn cut_to_length(mut self, measure: u32) -> (Plank, Plank) {
let leftover_plank = Plank {
length: self.length - measure,
endpiece: false,
new: false,
};
// Trim self to the new length
self.length = measure;
// In case the plank was new, mark it as cut
if self.new {
self.new = false;
}
// Return the original plank and the leftover
(self, leftover_plank)
}
}