私は完全な署名をコピー/ペーストしないようにFnMut(&[f32]) -> f32
、 で仕事をしたいが、私は別名のいくつかの種類をご紹介したいのですが、特定のFnMutのエイリアスを作成する方法はありますか?
type Boo = FnMut(&[f32]) -> f32;
fn f<F: Boo>(mut f: F) {}
は、コンパイラエラーが発生します。
error[E0404]: expected trait, found type alias `Boo`
--> src/main.rs:3:13
|
3 | fn f<F: Boo>(mut f: F) {}
| ^^^ type aliases cannot be used for traits
私は、試してみました:
trait Boo: FnMut(&[f32]) -> f32 {}
fn f<F: Boo>(mut f: F) {}
それがコンパイルされますが、私は別の場所で特色の代わりにBoo
を使用しようとした場合:
trait Boo: FnMut(&[f32]) -> f32 {}
struct X(Vec<Box<Boo>>);
私が取得:
error[E0191]: the value of the associated type `Output` (from the trait `std::ops::FnOnce`) must be specified
--> src/main.rs:3:18
|
3 | struct X(Vec<Box<Boo>>);
| ^^^ missing associated type `Output` value
は、私が代わりにFnMut(&[f32]) -> f32
の を使用することができ、特定のFnMut
のエイリアスを作成する方法はありますか?
はい、質問をする前にこのRFCについて読んでいます。問題は現在の安定版/ベータ版コンパイラで何をすべきかです。ハッキング/トリック/マクロ – user1244932