• SorteKanin@feddit.dkOP
    link
    fedilink
    arrow-up
    3
    ·
    22 days ago

    It’s a good question. I believe Vec uses a near-zero pointer but not actually a null pointer for an empty Vec. I think part of the reason is that it makes for better optimisation of Option<Vec<T>> which can then have the same size as Vec<T> with the pointer being null signifying None.

    Another big reason is that references are guaranteed not to be null and you can get a &[T] from an empty vec and that reference can’t be null. Even in a non empty vec you need to consider this if T is zero sized.