1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-03-25 07:32:40 +02:00

Set the correct element type in vector (#2500)

This commit is contained in:
TalonsLee 2024-12-12 23:02:54 +08:00 committed by GitHub
parent d7ed1944c2
commit 699cceadef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -48,17 +48,17 @@ Memory layout after allocating `pets`:
```bob ```bob
Stack Heap Stack Heap
.- - - - - - - - - - - - - -. .- - - - - - - - - - - - - - - - - - - - - - -. .- - - - - - - - - - - - - - - -. .- - - - - - - - - - - - - - - - - - - - - - -.
: : : : : : : :
: "pets: Vec<dyn Pet>" : : "data: Cat" +----+----+----+----+ : : "pets: Vec<Box<dyn Pet>>" : : "data: Cat" +----+----+----+----+ :
: +-----------+-------+ : : +-------+-------+ | F | i | d | o | : : +-----------+-------+ : : +-------+-------+ | F | i | d | o | :
: | ptr | o---+---+--. : | lives | 9 | +----+----+----+----+ : : | ptr | o---+-------+--. : | lives | 9 | +----+----+----+----+ :
: | len | 2 | : | : +-------+-------+ ^ : : | len | 2 | : | : +-------+-------+ ^ :
: | capacity | 2 | : | : ^ | : : | capacity | 2 | : | : ^ | :
: +-----------+-------+ : | : | '-------. : : +-----------+-------+ : | : | '-------. :
: : | : | data:"Dog"| : : : | : | data:"Dog"| :
: : | : | +-------+--|-------+ : : : | : | +-------+--|-------+ :
`- - - - - - - - - - - - - -' | : +---|-+-----+ | name | o, 4, 4 | : `- - - - - - - - - - - - - - - -' | : +---|-+-----+ | name | o, 4, 4 | :
`--+-->| o o | o o-|----->| age | 5 | : `--+-->| o o | o o-|----->| age | 5 | :
: +-|---+-|---+ +-------+----------+ : : +-|---+-|---+ +-------+----------+ :
: | | : : | | :