【发布时间】:2021-01-15 23:51:42
【问题描述】:
我想和戒指一起工作,所以我有一个特质 RingOps 并且我希望 float 成为其中的一部分。我认为float 实现了每个超类型,因此派生会很棒,但如果不是,该怎么做?
trait RingOps: Add<Output=Self> + Mul<Output=Self> + Eq + Debug
where Self: std::marker::Sized {}
impl RingOps for float {}
这是错误
error[E0412]: cannot find type `float` in this scope
--> src/main.rs:8:18
|
8 | impl RingOps for float {}
| ^^^^^ not found in this scope
error[E0277]: the trait bound `{float}: RingOps` is not satisfied
--> src/main.rs:44:32
|
13 | Input(&'a str, T),
| ----------------- required by `Circuit::Input`
...
44 | Box::new(Circuit::Input("a", 2.0)),
| ^^^ the trait `RingOps` is not implemented for `{float}`
【问题讨论】:
标签: rust numbers polymorphism traits parametric-polymorphism