@@ -3387,14 +3387,21 @@ more of the closure traits:
3387
3387
3388
3388
### Trait objects
3389
3389
3390
- Every trait item (see [ traits] ( #traits ) ) defines a type with the same name as
3391
- the trait. Traits that are object-safe (see [ RFC 255] [ rfc255 ] ) can be
3392
- instantiated as _ trait objects_ , which permit "late binding" of methods,
3393
- dispatched using _ virtual method tables_ ("vtables"). Whereas most calls to
3394
- trait methods are "early bound" (statically resolved) to specific
3395
- implementations at compile time, a call to a method on an trait objects is
3396
- only resolved to a vtable entry at compile time. The actual
3397
- implementation for each vtable entry can vary on an object-by-object basis.
3390
+ In Rust, a type like ` &SomeTrait ` or ` Box<SomeTrait> ` is called a _ trait object_ .
3391
+ Each instance of a trait object includes:
3392
+
3393
+ - a pointer to an instance of a type ` T ` that implements ` SomeTrait `
3394
+ - a _ virtual method table_ , often just called a _ vtable_ , which contains, for
3395
+ each method of ` SomeTrait ` that ` T ` implements, a pointer to ` T ` 's
3396
+ implementation (i.e. a function pointer).
3397
+
3398
+ The purpose of trait objects is to permit "late binding" of methods. A call to
3399
+ a method on a trait object is only resolved to a vtable entry at compile time.
3400
+ The actual implementation for each vtable entry can vary on an object-by-object
3401
+ basis.
3402
+
3403
+ Note that for a trait object to be instantiated, the trait must be
3404
+ _ object-safe_ . Object safety rules are defined in [ RFC 255] [ rfc255 ] .
3398
3405
3399
3406
Given a pointer-typed expression ` E ` of type ` &T ` or ` Box<T> ` , where ` T `
3400
3407
implements trait ` R ` , casting ` E ` to the corresponding pointer type ` &R ` or
0 commit comments