From efb457b8cf121b788728967b04cd2121c53167dd Mon Sep 17 00:00:00 2001 From: nwin Date: Thu, 23 Apr 2015 21:23:35 +0200 Subject: [PATCH 1/3] object type -> trait object Consistency. The book also refers to it as trait objects. --- src/doc/reference.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/doc/reference.md b/src/doc/reference.md index d918a320e63..a43fca7c19d 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -1555,7 +1555,7 @@ fn draw_twice(surface: Surface, sh: T) { } ``` -Traits also define an [object type](#object-types) with the same name as the +Traits also define an [trait object](#trait-objects) with the same name as the trait. Values of this type are created by [casting](#type-cast-expressions) pointer values (pointing to a type for which an implementation of the given trait is in scope) to pointers to the trait name, used as a type. @@ -2744,7 +2744,7 @@ A _method call_ consists of an expression followed by a single dot, an identifier, and a parenthesized expression-list. Method calls are resolved to methods on specific traits, either statically dispatching to a method if the exact `self`-type of the left-hand-side is known, or dynamically dispatching if -the left-hand-side expression is an indirect [object type](#object-types). +the left-hand-side expression is an indirect [trait object](#trait-objects). ### Field expressions @@ -3649,23 +3649,23 @@ call_closure(closure_no_args, closure_args); ``` -### Object types +### Trait objects Every trait item (see [traits](#traits)) defines a type with the same name as -the trait. This type is called the _object type_ of the trait. Object types +the trait. This type is called the _trait object_ of the trait. Trait objects permit "late binding" of methods, dispatched using _virtual method tables_ ("vtables"). Whereas most calls to trait methods are "early bound" (statically resolved) to specific implementations at compile time, a call to a method on an -object type is only resolved to a vtable entry at compile time. The actual +trait objects is only resolved to a vtable entry at compile time. The actual implementation for each vtable entry can vary on an object-by-object basis. Given a pointer-typed expression `E` of type `&T` or `Box`, where `T` implements trait `R`, casting `E` to the corresponding pointer type `&R` or -`Box` results in a value of the _object type_ `R`. This result is +`Box` results in a value of the _trait object_ `R`. This result is represented as a pair of pointers: the vtable pointer for the `T` implementation of `R`, and the pointer value of `E`. -An example of an object type: +An example of an trait object: ``` trait Printable { @@ -3685,7 +3685,7 @@ fn main() { } ``` -In this example, the trait `Printable` occurs as an object type in both the +In this example, the trait `Printable` occurs as an trait object in both the type signature of `print`, and the cast expression in `main`. ### Type parameters From a8f5989afbd32d76f65847e64f947851d3fc0059 Mon Sep 17 00:00:00 2001 From: nwin Date: Thu, 23 Apr 2015 21:25:09 +0200 Subject: [PATCH 2/3] typo --- src/doc/reference.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/reference.md b/src/doc/reference.md index a43fca7c19d..1b8525dde8c 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -3665,7 +3665,7 @@ implements trait `R`, casting `E` to the corresponding pointer type `&R` or represented as a pair of pointers: the vtable pointer for the `T` implementation of `R`, and the pointer value of `E`. -An example of an trait object: +An example of a trait object: ``` trait Printable { From 99fd7f213183bcf421ac881663ef2913ac4466b4 Mon Sep 17 00:00:00 2001 From: nwin Date: Thu, 23 Apr 2015 21:26:34 +0200 Subject: [PATCH 3/3] typo 2 --- src/doc/reference.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/reference.md b/src/doc/reference.md index 1b8525dde8c..af6db58c7e0 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -3685,7 +3685,7 @@ fn main() { } ``` -In this example, the trait `Printable` occurs as an trait object in both the +In this example, the trait `Printable` occurs as a trait object in both the type signature of `print`, and the cast expression in `main`. ### Type parameters