我想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
我可以使用 代替FnMut(&[f32]) -> f32
的別名?
是的,在提出問題之前,我已閱讀了關於此RFC的問題,現在問題是使用當前穩定/ beta編譯器進行的操作。黑客/技巧/ macroses – user1244932