【发布时间】:2019-10-08 09:40:56
【问题描述】:
当我看到这段代码时,我在chapter 19 of The Rust Programming Language
Box<dyn Fn() + Send + 'static>
它有什么作用,为什么里面有加号 (+)?我不记得在上一章遇到过这种情况。
Box::new(|| println!("hi")) 和 Box<dyn Fn() + Send + 'static> 怎么样?
【问题讨论】:
-
看看rust by example 你还应该重读 rust-lang 书的第 10 章,
+运算符用于结合货物文档的边界:When working with generics, the type parameters often must use traits as bounds to stipulate what functionality a type implements. For example, the following example uses the trait Display to print and so it requires T to be bound by Display; that is, T must implement Display.在你的情况下Box包含实现Send和'static生命周期的动态对象