No description
Find a file
2021-12-22 20:51:51 +01:00
src pub use iter::IterMut 2021-12-22 20:51:51 +01:00
.gitignore initial commit 2021-12-20 14:00:10 +01:00
Cargo.toml initial commit 2021-12-20 14:00:10 +01:00
LICENSE Create LICENSE 2021-12-22 18:46:16 +01:00
README.md add fancy indexing and getting 2021-12-21 12:04:42 +01:00
rust-toolchain.toml upgrade nightly 2021-12-22 14:51:34 +01:00

A Vec<T: ?Sized>

It's implemented by laying out the elements in memory contiguously like alloc::vec::Vec

Layout

A Vechonk is 4 usize long. It owns a single allocation, containing the elements and the metadata. The elements are laid out contiguously from the front, while the metadata is laid out contiguously from the back. Both grow towards the center until they meet and get realloced to separate them again.


            Vechonk<str>
            ╭──────────────────────────────────╮
            │ ptr   | len   | cap  | elem_size │
            ╰──────────────────────────────────╯
               │               │        │
               │               ╰────────│──────────────────────────────────────╮
               │                        │                                      │
               │               ╭────────╯                                      │
        Heap   ▼               ▼                                               ▼
        ╭────────────┬─────────┬─────────────────┬──────────────┬──────────────╮
value   │ "hello"    │ "uwu"   │  <uninit>       │ 0 - 5        │ 5 - 3        │
        ├────────────┼─────────┼─────────────────┼──────────────┼──────────────┤
 size   │ dynamic    │ dynamic │  rest of alloc  │ usize + meta │ usize + meta │
        ╰────────────┴─────────┴─────────────────┴──────────────┴──────────────╯
            ▲            ▲                          │              │
            ╰────────────│──────────────────────────╯              │
                         ╰─────────────────────────────────────────╯