錆1.15では、私はファイルフォーマットを解析する&を読み上げるために抽象的な特性を作成しました。私は内部にこの一般的な特性を持つ構造体を作成しようとしています。一般的な形質である一般的な特性を持つ構造
私はこの形質を持っている:
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);
}
は、私はこれを実装して何かへの参照を持つ構造体を作りたいです。
struct MyIterThing<'a, T: MyReader<R>+'a> {
inner: &'a mut T,
}
は、次のエラーを与える:
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
"error[E0243]: wrong number of type arguments: expected 1, found 0"
は、
T: MyReader<R: Read>+'a
は、低レベルの構文エラーを与え、それはそこに
:
を期待していません。
そして、これはどちらか動作しません:
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`
は、どのように私は私のMyIterThing
構造体を作成するのですか?
右、謝罪します。コメントを押した直後に気づいた。 :x 「PhantomData」の作成に従ったことはありますか? –
@ E_net4どうすればいいのか分かりません。 – Rory
http://stackoverflow.com/a/40487993/1233251 –