Skip to content

Commit

Permalink
feat: impl the Default trait
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlad2001MFS committed Jan 26, 2024
1 parent 0232305 commit 4b855ab
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,7 @@ impl<T> Grid<T> {
T: Default,
{
if rows == 0 || cols == 0 {
return Self {
data: Vec::new(),
rows: 0,
cols: 0,
order,
};
return Self::default();
}
let mut data = Vec::new();
data.resize_with(rows.checked_mul(cols).unwrap(), T::default);
Expand Down Expand Up @@ -397,12 +392,7 @@ impl<T> Grid<T> {
T: Clone,
{
if rows == 0 || cols == 0 {
return Self {
data: Vec::new(),
rows: 0,
cols: 0,
order,
};
return Self::default();
}
Self {
data: vec![data; rows.checked_mul(cols).unwrap()],
Expand Down Expand Up @@ -1471,6 +1461,17 @@ impl<T> Grid<T> {
}
}

impl<T> Default for Grid<T> {
fn default() -> Self {
Self {
data: Vec::default(),
cols: 0,
rows: 0,
order: Order::default(),
}
}
}

impl<T: Clone> Clone for Grid<T> {
fn clone(&self) -> Self {
Grid {
Expand Down

0 comments on commit 4b855ab

Please sign in to comment.