In Rust 1.15, I have created a trait to abstract over reading & parsing file format(s). I'm trying to create a struct which has this generic trait inside.
I have this trait:
use std::io::Read;
trait MyReader<R: Read> {
fn new(R) -> Self;
fn into_inner(self) -> R;
fn get_next(&mut self) -> Option<u32>;
fn do_thingie(&mut self);
}
I want to make a struct which has a reference to something that implements this.
struct MyIterThing<'a, T: MyReader<R>+'a> {
inner: &'a mut T,
}
Gives the following error:
error[E0412]: type name `R` is undefined or not in scope
--> <anon>:11:36
|
11 | struct MyIterThing<'a, T: MyReader<R>+'a> {
| ^ undefined or not in scope
|
= help: no candidates by the name of `R` found in your project; maybe you misspelled the name or forgot to import an external crate?
T: MyReader+'a
, I get the error: "error[E0243]: wrong number of type arguments: expected 1, found 0"
, T: MyReader<R: Read>+'a
gives a low level syntax error, it's not expecting a :
there.
And this doesn't work either:
error[E0392]: parameter `R` is never used
--> <anon>:11:24
|
11 | struct MyIterThing<'a, R: Read, T: MyReader<R>+'a> {
| ^ unused type parameter
|
= help: consider removing `R` or using a marker such as `std::marker::PhantomData`
How do I create my MyIterThing
struct?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…