Hi,
First of all, thanks for the great library!
I am trying to implement a data structure on top of a VectorN
, but I struggle with deriving the Copy
trait, because the b: VectorN<S, D>
does not implement Copy
.
As far as I can understand, however, this trait is implemented on https://github.com/rustsim/nalgebra/blob/master/src/base/matrix.rs#L75.
My (very dirty, sorry) project can be found at https://github.com/hovind/ad/tree/08146cf83151e842ae5ad08f80de0183f247169f.
Sorry for the poor description, this is my first project in rust, and I am struggling to get the grasp of it.
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct Dual<S, D>
where
S: Real,
D: Dim,
DefaultAllocator: Allocator<S, D>,
{
a: S,
b: VectorN<S, D>,
}
impl<S, D> Dual<S, D>
where
S: Real,
D: Dim + DimName,
DefaultAllocator: Allocator<S, D>,
{
pub fn new(x : VectorN<S, D>) -> VectorN<Dual<S, D>, D> {
VectorN::<Dual<S, D>, D>::from_fn(|i : usize, _| -> Dual<S, D> {
Dual {
a: x[i],
b: VectorN::<S, D>::from_fn(|j : usize, _| -> S {
if i == j {
S::one()
} else {
S::zero()
}
}),
}
})
}
}