Skip to content

Commit b251e25

Browse files
author
Nick Hamann
committed
---
yaml --- r: 206847 b: refs/heads/beta c: b2f486f h: refs/heads/master i: 206845: b769c26 206843: b41afe2 206839: b175b41 206831: 7557ffe 206815: ebda970 206783: 79ee0df 206719: 40baf0d 206591: 53c93c3 206335: 43d6830 205823: 0ec64e0 204799: 0c821d1 v: v3
1 parent 4709c24 commit b251e25

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
@@ -29,7 +29,7 @@ refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
2929
refs/heads/automation-fail: 1bf06495443584539b958873e04cc2f864ab10e4
3030
refs/heads/batch: b7fd822592a4fb577552d93010c4a4e14f314346
3131
refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
32-
refs/heads/beta: 857a12a01ed8a9249cea8f48b39a0f8bdfd95cbd
32+
refs/heads/beta: b2f486feafa99124479d1b5e74c9acc6ed7cc233
3333
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3434
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
3535
refs/heads/tmp: 579e31929feff51dcaf8d444648eff8de735f91a

branches/beta/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)