-
Notifications
You must be signed in to change notification settings - Fork 135
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
struct
built on top of pub trait Num
can't compile if pub trait Num
doesn't impl Debug
#318
Comments
#[test]
fn test_debug_trait_impl() {
use num_traits::Num;
use std::ops::Add;
pub struct LengthNArrayOfTypeT<const N: usize, T: Num>([T; N]);
impl<const N: usize, T: Num + Clone> Add for LengthNArrayOfTypeT<N, T> {
type Output = Self;
fn add(self, rhs: Self) -> Self {
LengthNArrayOfTypeT(
self.0
.iter()
.zip(rhs.0.iter())
.map(|(a, b)| a.clone() + b.clone())
.collect::<Vec<T>>()
.try_into()
.unwrap(),
)
}
}
} is an example of code that can't compile because of this issue. |
You should add
The place your example encounters this doesn't have anything to do with being a numeric type. The error is from your Or you could rewrite this to update the value in-place: fn add(mut self, rhs: Self) -> Self {
for (a, b) in std::iter::zip(&mut self.0, rhs.0) {
*a = a.clone() + b;
}
self
} And with |
I know. I started needing to add it everywhere, so I started looking into different approaches.
Thank you for the suggestion. |
You could define your own extended trait: trait MyNum: num_traits::Num + Clone + Debug {}
impl<T> MyNum for T where T: num_traits::Num + Clone + Debug {} |
No description provided.
The text was updated successfully, but these errors were encountered: