使用以下代码:
use std::io::Result;
pub trait Frame {
type Sample;
}
pub trait WriteFrames<F: Frame> {
fn write_frames(&mut self, frames: &[F]) -> Result<usize>;
}
pub trait ReadFrames<F: Frame> {
fn read_frames(&mut self, frames: &mut [F]) -> Result<usize>;
}
pub trait FrameBuffer: ReadFrames<Self::Frame> + WriteFrames<Self::Frame> {
type Frame: Frame;
}
我收到此错误:
Compiling playground v0.0.1 (/playground)
error[E0391]: cycle detected when computing the supertraits of `FrameBuffer`
--> src/lib.rs:15:1
|
15 | pub trait FrameBuffer: ReadFrames<Self::Frame> + WriteFrames<Self::Frame> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: ...which again requires computing the supertraits of `FrameBuffer`, completing the cycle
note: cycle used when collecting item types in top-level module
--> src/lib.rs:15:1
|
15 | pub trait FrameBuffer: ReadFrames<Self::Frame> + WriteFrames<Self::Frame> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0391`.
error: Could not compile `playground`.
To learn more, run the command again with --verbose.
我应该如何对代码进行建模以解决此错误?
我想拥有一个FrameBuffer
类型的特征,该特征指定了一种Frame
类型,并且对于该WriteFrames
类型需要ReadFrames
和Frame
。