-
Notifications
You must be signed in to change notification settings - Fork 2k
Closed
Labels
waiting for authorWaiting on the issue author to replyWaiting on the issue author to reply
Description
https://google.github.io/comprehensive-rust/generics/trait-objects.html has this diagram:
comprehensive-rust/src/generics/trait-objects.md
Lines 41 to 67 in c212a47
| ```bob | |
| Stack Heap | |
| .- - - - - - - - - - - - - -. .- - - - - - - - - - - - - - - - - - - - - - - -. | |
| : : : : | |
| : xs : : : | |
| : +-----------+-------+ : : +-----+-----+ : | |
| : | ptr | o---+---+-----+-->| o o | o o | : | |
| : | len | 2 | : : +-|-|-+-|-|-+ : | |
| : | capacity | 2 | : : | | | | +----+----+----+----+----+ : | |
| : +-----------+-------+ : : | | | '-->| H | e | l | l | o | : | |
| : : : | | | +----+----+----+----+----+ : | |
| `- - - - - - - - - - - - - -' : | | | : | |
| : | | | +-------------------------+ : | |
| : | | '---->| "<str as Display>::fmt" | : | |
| : | | +-------------------------+ : | |
| : | | : | |
| : | | +-------------------------+ : | |
| : | '-->| "<i32 as Display>::fmt" | : | |
| : | +-------------------------+ : | |
| : | : | |
| : | +----+----+----+----+ : | |
| : '---->| 7b | 00 | 00 | 00 | : | |
| : +----+----+----+----+ : | |
| : : | |
| : : | |
| '- - - - - - - - - - - - - - - - - - - - - - - -' | |
| ``` |
Quoting https://doc.rust-lang.org/reference/types/trait-object.html
Each instance of a pointer to a trait object includes:
- a pointer to an instance of a type T that implements SomeTrait
- a virtual method table, often just called a vtable, which contains, for each method of SomeTrait and its supertraits that T implements, a pointer to T's implementation (i.e. a function pointer).
It seems the diagram here draws one object as (instance, vtable) and the second as (vtable, instance). Consistency would help, and based on https://doc.rust-lang.org/reference/types/trait-object.html it seems (instance, vtable) is the safer assumption.
Metadata
Metadata
Assignees
Labels
waiting for authorWaiting on the issue author to replyWaiting on the issue author to reply