質問編集履歴

1

再現したものを追加し、エラーメッセージも追加

2021/08/19 14:28

投稿

hidekiti
hidekiti

スコア23

test CHANGED
File without changes
test CHANGED
@@ -8,37 +8,39 @@
8
8
 
9
9
  ```rust
10
10
 
11
+
12
+
13
+ use std::{ops::Mul, process::Output};
14
+
15
+ use num::{Signed, Unsigned};
16
+
17
+
18
+
19
+ struct Sample<T>(T);
20
+
21
+ // Unsigedなprimitive型に対する計算(負の場合を考慮しない)
22
+
11
- impl Mul<u32> for Decimal<u32> {
23
+ impl<T> Mul<u32> for Sample<T> {
12
24
 
13
25
  type Output = Self;
14
26
 
15
27
  fn mul(self, rhs: u32) -> Self::Output {
16
28
 
17
- Decimal(self.0.wrapping_mul(rhs.to_u32().unwrap()))
29
+ todo!()
18
30
 
19
31
  }
20
32
 
21
33
  }
22
34
 
23
- impl<S: 'static + Neg<Output = S>, T: AsPrimitive<S> + WrappingMul + Unsigned> Mul<S>
35
+ // Signedなprimitive型に対する計算(負の場合も実装する)
24
36
 
25
- for Decimal<T>
37
+ impl<S:Signed + 'static + Copy,T> Mul<S> for Sample<T> {
26
-
27
- {
28
38
 
29
39
  type Output = Self;
30
40
 
31
41
  fn mul(self, rhs: S) -> Self::Output {
32
42
 
33
- if rhs < 0 {
34
-
35
- -(self * rhs as u32)
36
-
37
- } else {
43
+ todo!()
38
-
39
- self * rhs as u32
40
-
41
- }
42
44
 
43
45
  }
44
46
 
@@ -52,8 +54,8 @@
52
54
 
53
55
  ```
54
56
 
55
- conflicting implementations of trait `std::ops::Mul<u32>` for type `Decimal<u32>`
57
+ conflicting implementations of trait `std::ops::Mul<u32>` for type `Sample<_>`
56
58
 
57
- upstream crates may add a new impl of trait `std::ops::Neg` for type `u32` in future versionsrustcE0119>
59
+ upstream crates may add a new impl of trait `num::Signed` for type `u32` in future versions
58
60
 
59
61
  ```