2015-04-03 217 views
2

類型別名在Rust中的工作原理如何?Rust中的類型別名

我一直在研究一些老鏽代碼破損不是我寫的,發現Thunk::new(...)導致此錯誤:

error: type `Box<alloc::boxed::FnBox<_, Output=_> + Send>` 
    does not implement any method in scope named `new` 

Thunk被定義爲:

type Thunk<'a, A =(), R =()> = Box<FnBox<A, Output=R> + Send + 'a>; 

我想Alias::method在以前版本的Rust中沒有工作?我應該如何將Thunk::new變成有效的東西?它是否缺少Box或某物的導入?

回答

4

Thunk::new因爲它工作,因爲它used to be a struct而不是一個類型別名。這是前兩天更改的:Add (unstable) FnBox trait as a nicer replacement for Thunk.

要解決此問題,請將Thunk::new替換爲Box::new,如在該PR中的整個標準庫中所做的那樣。還將thunk.invoke()更改爲thunk()

+0

完美答案。謝謝! – 2015-04-03 15:32:20