Skip to content

Commit 623c58b

Browse files
author
Nick Hamann
committed
---
yaml --- r: 205188 b: refs/heads/auto c: b2f486f h: refs/heads/master v: v3
1 parent 9c0e0aa commit 623c58b

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: 857a12a01ed8a9249cea8f48b39a0f8bdfd95cbd
13+
refs/heads/auto: b2f486feafa99124479d1b5e74c9acc6ed7cc233
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/doc/reference.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3510,13 +3510,21 @@ more of the closure traits:
35103510

35113511
### Trait objects
35123512

3513-
Every trait item (see [traits](#traits)) defines a type with the same name as
3514-
the trait. This type is called the _trait object_ of the trait. Trait objects
3515-
permit "late binding" of methods, dispatched using _virtual method tables_
3516-
("vtables"). Whereas most calls to trait methods are "early bound" (statically
3517-
resolved) to specific implementations at compile time, a call to a method on an
3518-
trait objects is only resolved to a vtable entry at compile time. The actual
3519-
implementation for each vtable entry can vary on an object-by-object basis.
3513+
In Rust, a type like `&SomeTrait` or `Box<SomeTrait>` is called a _trait object_.
3514+
Each instance of a trait object includes:
3515+
3516+
- a pointer to an instance of a type `T` that implements `SomeTrait`
3517+
- a _virtual method table_, often just called a _vtable_, which contains, for
3518+
each method of `SomeTrait` that `T` implements, a pointer to `T`'s
3519+
implementation (i.e. a function pointer).
3520+
3521+
The purpose of trait objects is to permit "late binding" of methods. A call to
3522+
a method on a trait object is only resolved to a vtable entry at compile time.
3523+
The actual implementation for each vtable entry can vary on an object-by-object
3524+
basis.
3525+
3526+
Note that for a trait object to be instantiated, the trait must be
3527+
_object-safe_. Object safety rules are defined in [RFC 255][rfc255].
35203528

35213529
Given a pointer-typed expression `E` of type `&T` or `Box<T>`, where `T`
35223530
implements trait `R`, casting `E` to the corresponding pointer type `&R` or

0 commit comments

Comments
 (0)