this post was submitted on 01 Oct 2026
35 points (100.0% liked)

Rust

8320 readers
32 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 3 years ago
MODERATORS
top 8 comments
sorted by: hot top controversial new old

Stable variadic functions is cool AF!

[–] TehPers@beehaw.org 3 points 1 week ago* (last edited 1 week ago)

The extern variadic functions are pretty cool. What I'm actually most excited about is what just moved to beta, though. In particular, stabilization of both Allocator and ! are now in beta.

[–] arendjr@programming.dev 2 points 1 week ago (2 children)

Vec::into_parts() returns a NonNull pointer, but isn’t the pointer allowed to be null if the vector is empty? I would expect that this method should be able to return a null pointer, but I’m probably missing something…

[–] SorteKanin@feddit.dk 3 points 1 week ago* (last edited 1 week ago) (1 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.

[–] arendjr@programming.dev 2 points 1 week ago (2 children)

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

[–] SorteKanin@feddit.dk 4 points 1 week ago

I looked it up, it's a pointer equal to the alignment of the type. So usually some small power of two.

[–] fil@programming.dev 2 points 1 week ago* (last edited 1 week ago)

Vec::<u8>::new().as_ptr() = 0x0000000000000001

playground

[–] BB_C@programming.dev 2 points 1 week ago

To add to the other answers. Usually, the easiest way to answer such questions is to click on source. Then in this case, you would immediately see this comment:

// SAFETY: A `Vec` always has a non-null pointer.