Let's explore these two types in more detail; 因为他们是标记trait ,甚至都不需要实现任何方法。 As marker traits , they don't even have any methods to implement. 对象的类型和行为是由class和trait 来描述的。 Types and behaviors of objects are described by classes and traits . 所有的闭包都实现了trait Fn、FnMut或FnOnce中的一个。 All closures implement one of the traits Fn, FnMut, or FnOnce. What the implementation of the trait provided by derive does.
这些trait 之间的差异是它们如何使用self参数。 The big difference between these traits is how they take the self parameter. 自PHP5.4.0起,PHP实现了一种代码复用的方法,称为trait 。 As of PHP 5.4.0, PHP implements a method of code reuse called Traits . Closures are represented by traits , which means you can't return closures directly. 事实上,之前我们已经见过了,不过是另一个动态大小类型:trait 。 In fact, you have already seen this before, but with a different dynamically sized type: traits . 注意:你不可能凭空就知道应该use哪个trait 以及该从crate中调用哪个方法。 Note: You won't just know which traits to use and which methods and functions to call from a crate. 如果一个类型实现了Copytrait ,原始所有者的值不会无效,仍然可以使用。 If a type implements the Copy trait , the original owner's value won't be invalidated, and can still be used. 然而有两个并发概念是内嵌于语言中的:std::marker中的Sync和Sendtrait 。 However, two concurrency concepts are embedded in the language: the std::marker traits Sync and Send. 第一点,Trait 不能有任何“类”参数,也就是说,传递给类的主构造器的参数。 First, a trait cannot have any“class” parameters, i.e., parameters passed to the primary constructor of a class. 有两个并发概念内嵌于语言中:std::marker中的Sync和Sendtrait 。 There are two concurrency concepts embedded in the language, however: the std::marker traits Sync and Send. 因为T的trait bound,我们可以传递任何NewsArticle或Tweet的实例调用notify。 Because of the trait bound on T, we can call notify and pass in any instance of NewsArticle or Tweet. 另外还会简要的讲到闭包、迭代器和trait 对象,他们分别会在第十三章和第十七章中详细介绍。 We will also briefly introduce closures, iterators, and trait objects, which Chapters 13 and 17 will cover in detail. 注意:trait 类似于其他语言中的常被称为接口(interfaces)的功能,虽然有一些不同。 Note: Traits are similar to a feature often called‘interfaces' in other languages, though with some differences. 这时你或许推导出以下结论:Trait 就像是带有具体方法的Java接口,不过其实它能做的更多。 At this point you might think that traits are like C/Java interfaces with concrete methods, but they can actually do much more. Trait和trait bounds保证了即使类型是泛型的,这些类型也会拥有所需要的行为。 Traits and trait bounds ensure that even though the types are generic, those types will have the behavior the code needs. 我们还没有讨论到trait ,不过目前,你可以理解为一个为特定类型增加额外行为的标记。 We haven't discussed traits yet, but for now, you can think of them as an annotation to a particular type that adds extra behavior. Trait 定义是一种将方法签名组合起来的方法,目的是定义一个实现某些目的所必需的行为的集合。Trait definitions are a way to group method signatures together to define a set of behaviors necessary to accomplish some purpose. 样板破坏者-Case类、trait 及其他高级特性均可消除在代码中其他地方重复操作的需要。 Boilerplate busters- Case classes, traits , and other advanced features can all but eliminate the need to repeat yourself anywhere in the code. Accordingtotrait theories,introversionand外向是一个持续的维度的一部分,中间有许多人。 According to trait theories, introversion and extraversion are part of a continuous dimension, with many people in the middle. 但是一定有别的东西,一些特殊的人类trait -one这些细微的差别,超出了纯粹的肯教授。 But there must be something else in the way, some special human trait - one of those subtle differences that are beyond the ken of mere professors. 所有基本类型都实现了Copytrait ,因此他们的所有权并不像你想象的那样遵循“所有权规则”被移动。 All primitive types implement the Copy trait and their ownership is therefore not moved like one would assume, following the'ownership rules'. Eqtrait 只能应用于那些实现了PartialEq的类型,但并非所有实现了PartialEq的类型都可以实现Eq。 The Eq trait can only be applied to types that also implement PartialEq, although not all types that implement PartialEq can implement Eq. 但最近对人格科学研究的综述指出,性格(personalitytrait )可通过持续干预和重大生活事件而改变。 But a review of recent research in personality science points to the possibility that personality traits can change through persistent intervention and major life events. Levy解释说,Trait Amplified大麻素饮料实际上含有100%水溶性大麻素,并且不需要搅拌。 Levy explained that Trait Amplified cannabinoids beverages would actually contain 100% water soluble cannabinoids and that no agitation is required. 当断言失败时,这些宏会使用调试格式打印出其参数,这意味着被比较的值必需实现了PartialEq和Debugtrait 。 When the assertions fail, these macros print their arguments using debug formatting, which means the values being compared must implement the PartialEq and Debug traits . Ordtrait 实现了cmp方法,它返回一个Ordering而不是Option<Ordering>,因为总存在一个合法的顺序。 The Ord trait implements the cmp method, which returns an Ordering rather than an Option<Ordering> because a valid ordering will always be possible.
Display more examples
Results: 111 ,
Time: 0.0165