在Rust中键入别名

时间:2015-04-03 15:15:41

标签: alias rust

类型别名究竟在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或其他内容的导入?

1 个答案:

答案 0 :(得分:4)

Thunk::new曾经工作过,因为used to bestruct而不是类型别名。这在两天前发生了变化:Add (unstable) FnBox trait as a nicer replacement for Thunk.

要解决此问题,请将Thunk::new替换为Box::new,同样在该PR中的标准库中执行此操作。同时将thunk.invoke()更改为thunk()