Skip to content

Commit 4b855ab

Browse files
committed
feat: impl the Default trait
1 parent 0232305 commit 4b855ab

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

Diff for: src/lib.rs

+13-12
Original file line numberDiff line numberDiff line change
@@ -352,12 +352,7 @@ impl<T> Grid<T> {
352352
T: Default,
353353
{
354354
if rows == 0 || cols == 0 {
355-
return Self {
356-
data: Vec::new(),
357-
rows: 0,
358-
cols: 0,
359-
order,
360-
};
355+
return Self::default();
361356
}
362357
let mut data = Vec::new();
363358
data.resize_with(rows.checked_mul(cols).unwrap(), T::default);
@@ -397,12 +392,7 @@ impl<T> Grid<T> {
397392
T: Clone,
398393
{
399394
if rows == 0 || cols == 0 {
400-
return Self {
401-
data: Vec::new(),
402-
rows: 0,
403-
cols: 0,
404-
order,
405-
};
395+
return Self::default();
406396
}
407397
Self {
408398
data: vec![data; rows.checked_mul(cols).unwrap()],
@@ -1471,6 +1461,17 @@ impl<T> Grid<T> {
14711461
}
14721462
}
14731463

1464+
impl<T> Default for Grid<T> {
1465+
fn default() -> Self {
1466+
Self {
1467+
data: Vec::default(),
1468+
cols: 0,
1469+
rows: 0,
1470+
order: Order::default(),
1471+
}
1472+
}
1473+
}
1474+
14741475
impl<T: Clone> Clone for Grid<T> {
14751476
fn clone(&self) -> Self {
14761477
Grid {

0 commit comments

Comments
 (0)