类型别名究竟在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
或其他内容的导入?
答案 0 :(得分:4)
Thunk::new
曾经工作过,因为used to be是struct
而不是类型别名。这在两天前发生了变化:Add (unstable) FnBox trait as a nicer replacement for Thunk
.
要解决此问题,请将Thunk::new
替换为Box::new
,同样在该PR中的标准库中执行此操作。同时将thunk.invoke()
更改为thunk()
。