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 Debug trait to pub trait Num #319

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#[cfg(feature = "std")]
extern crate std;

use core::fmt;
use core::fmt::{self, Debug};
use core::num::Wrapping;
use core::ops::{Add, Div, Mul, Rem, Sub};
use core::ops::{AddAssign, DivAssign, MulAssign, RemAssign, SubAssign};
Expand Down Expand Up @@ -64,7 +64,7 @@ pub mod sign;

/// The base trait for numeric types, covering `0` and `1` values,
/// comparisons, basic numeric operations, and string conversion.
pub trait Num: PartialEq + Zero + One + NumOps {
pub trait Num: PartialEq + Zero + One + NumOps + Debug {
type FromStrRadixErr;

/// Convert from a string and radix (typically `2..=36`).
Expand Down Expand Up @@ -203,7 +203,7 @@ impl fmt::Display for ParseFloatError {
FloatErrorKind::Invalid => "invalid float literal",
};

description.fmt(f)
fmt::Display::fmt(description, f)
}
}

Expand Down
20 changes: 20 additions & 0 deletions tests/num_impl_debug.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#[test]
fn test_if_num_impl_debug() {
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(),
)
}
}
}