假设我具有以下特征
pub trait MyTrait {
const A_NUMBER: usize;
fn run(&self, data: [u32; Self::A_NUMBER]) -> u32;
}
这会导致以下输出:
error[E0599]: no associated item named `A_NUMBER` found for type `Self` in the current scope
--> src/opcode.rs:8:37
|
8 | fn run(&self, data: [u32; Self::A_NUMBER]) -> u32;
| ^^^^^^^^ associated item not found in `Self`
|
= help: items from traits can only be used if the type parameter is bounded by the trait
help: the following trait defines an item `A_NUMBER`, perhaps you need to restrict type parameter `Self` with it:
|
6 | Self: opcode::MyTrait
确定此请求毫无意义吗?如果我已经为我相信MyTrait
引用的结构实现了特征Self
,那肯定意味着Self
实现了MyTrait
吗?我该如何在特征函数中正确使用特征常数,或者只是不可能?