【问题标题】:What is the plus symbol (+) in generics? [duplicate]泛型中的加号 (+) 是什么? [复制]
【发布时间】:2019-10-08 09:40:56
【问题描述】:

当我看到这段代码时,我在chapter 19 of The Rust Programming Language

Box<dyn Fn() + Send + 'static>

它有什么作用,为什么里面有加号 (+)?我不记得在上一章遇到过这种情况。

Box::new(|| println!("hi"))Box&lt;dyn Fn() + Send + 'static&gt; 怎么样?

【问题讨论】:

  • 看看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 生命周期的动态对象

标签: generics rust


【解决方案1】:

感谢@Asya Corbeau 让我回到第 10 章,它是 Specifying Multiple Trait Bounds with the + Syntax

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-11
    • 2013-07-11
    • 2012-07-15
    • 2018-09-30
    • 1970-01-01
    • 2021-07-27
    • 2014-04-14
    相关资源
    最近更新 更多