you are viewing a single comment's thread
view the rest of the comments
[–] [S] 3 points 1 month ago* (3 children)

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> which can then have the same size as Vec 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.

  • source
  • parent
  • hideshow 3 child comments
  • [–] 2 points 1 month ago (2 children)

    Ah yes, that makes sense. Curious what it points to then when empty…

  • source
  • parent
  • hideshow 2 child comments