@@ -3510,13 +3510,21 @@ more of the closure traits:
3510
3510
3511
3511
### Trait objects
3512
3512
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 ] .
3520
3528
3521
3529
Given a pointer-typed expression ` E ` of type ` &T ` or ` Box<T> ` , where ` T `
3522
3530
implements trait ` R ` , casting ` E ` to the corresponding pointer type ` &R ` or
0 commit comments