Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Default impl for Unit #1444

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/base/unit.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use std::fmt;
use std::ops::Deref;

use num::{One, Zero};

#[cfg(feature = "serde-serialize-no-std")]
use serde::{Deserialize, Deserializer, Serialize, Serializer};

use crate::allocator::Allocator;
use crate::base::DefaultAllocator;
use crate::storage::RawStorage;
use crate::{Dim, Matrix, OMatrix, RealField, Scalar, SimdComplexField, SimdRealField};
use crate::{Dim, DimName, Matrix, OMatrix, RealField, Scalar, SimdComplexField, SimdRealField};

#[cfg(feature = "rkyv-serialize")]
use rkyv::bytecheck;
Expand Down Expand Up @@ -71,6 +73,18 @@ impl<'de, T: Deserialize<'de>> Deserialize<'de> for Unit<T> {
}
}

impl<T, R, C> Default for Unit<OMatrix<T, R, C>>
where
T: Scalar + Zero + One,
R: DimName,
C: DimName,
DefaultAllocator: Allocator<R, C>,
{
fn default() -> Self {
Self::new_unchecked(OMatrix::<T, R, C>::identity())
}
}

impl<T, R, C, S> PartialEq for Unit<Matrix<T, R, C, S>>
where
T: Scalar + PartialEq,
Expand Down
Loading