From a118e61649bc0b6e0fbac7893729585e416a7c2d Mon Sep 17 00:00:00 2001 From: TalonsLee Date: Thu, 5 Dec 2024 14:54:56 +0800 Subject: [PATCH 1/2] Set the correct element type in vector --- src/smart-pointers/trait-objects.md | 56 ++++++++++++++--------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/smart-pointers/trait-objects.md b/src/smart-pointers/trait-objects.md index 7f0e3f51df0..4149815c7d8 100644 --- a/src/smart-pointers/trait-objects.md +++ b/src/smart-pointers/trait-objects.md @@ -48,34 +48,34 @@ Memory layout after allocating `pets`: ```bob Stack Heap -.- - - - - - - - - - - - - -. .- - - - - - - - - - - - - - - - - - - - - - -. -: : : : -: "pets: Vec" : : "data: Cat" +----+----+----+----+ : -: +-----------+-------+ : : +-------+-------+ | F | i | d | o | : -: | ptr | o---+---+--. : | lives | 9 | +----+----+----+----+ : -: | len | 2 | : | : +-------+-------+ ^ : -: | capacity | 2 | : | : ^ | : -: +-----------+-------+ : | : | '-------. : -: : | : | data:"Dog"| : -: : | : | +-------+--|-------+ : -`- - - - - - - - - - - - - -' | : +---|-+-----+ | name | o, 4, 4 | : - `--+-->| o o | o o-|----->| age | 5 | : - : +-|---+-|---+ +-------+----------+ : - : | | : - `- - -| - - |- - - - - - - - - - - - - - - - -' - | | - | | "Program text" - .- - -| - - |- - - - - - - - - - - - - - - - -. - : | | vtable : - : | | +----------------------+ : - : | `----->| "::talk" | : - : | +----------------------+ : - : | vtable : - : | +----------------------+ : - : '----------->| "::talk" | : - : +----------------------+ : - : : - '- - - - - - - - - - - - - - - - - - - - - - -' +.- - - - - - - - - - - - - - - -. .- - - - - - - - - - - - - - - - - - - - - - -. +: : : : +: "pets: Vec>" : : "data: Cat" +----+----+----+----+ : +: +-----------+-------+ : : +-------+-------+ | F | i | d | o | : +: | ptr | o---+---+---+--. : | lives | 9 | +----+----+----+----+ : +: | len | 2 | : | : +-------+-------+ ^ : +: | capacity | 2 | : | : ^ | : +: +-----------+-------+ : | : | '-------. : +: : | : | data:"Dog"| : +: : | : | +-------+--|-------+ : +`- - - - - - - - - - - - - - - -' | : +---|-+-----+ | name | o, 4, 4 | : + `--+-->| o o | o o-|----->| age | 5 | : + : +-|---+-|---+ +-------+----------+ : + : | | : + `- - -| - - |- - - - - - - - - - - - - - - - -' + | | + | | "Program text" + .- - -| - - |- - - - - - - - - - - - - - - - -. + : | | vtable : + : | | +----------------------+ : + : | `----->| "::talk" | : + : | +----------------------+ : + : | vtable : + : | +----------------------+ : + : '----------->| "::talk" | : + : +----------------------+ : + : : + '- - - - - - - - - - - - - - - - - - - - - - -' ```
From 3c33949bf0e057867eff378329ab67e4f7e90478 Mon Sep 17 00:00:00 2001 From: Martin Geisler Date: Fri, 6 Dec 2024 14:33:14 +0100 Subject: [PATCH 2/2] Apply suggestions from code review --- src/smart-pointers/trait-objects.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/smart-pointers/trait-objects.md b/src/smart-pointers/trait-objects.md index 4149815c7d8..f66b27b6ef6 100644 --- a/src/smart-pointers/trait-objects.md +++ b/src/smart-pointers/trait-objects.md @@ -52,7 +52,7 @@ Memory layout after allocating `pets`: : : : : : "pets: Vec>" : : "data: Cat" +----+----+----+----+ : : +-----------+-------+ : : +-------+-------+ | F | i | d | o | : -: | ptr | o---+---+---+--. : | lives | 9 | +----+----+----+----+ : +: | ptr | o---+-------+--. : | lives | 9 | +----+----+----+----+ : : | len | 2 | : | : +-------+-------+ ^ : : | capacity | 2 | : | : ^ | : : +-----------+-------+ : | : | '-------. :