With this code:
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;
}
I get this error:
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.
How should I model my code to get around this error?
I want to have a FrameBuffer
trait that specified a Frame
type, and requires WriteFrames
and ReadFrames
for that Frame
type.