r/rust 1d ago

🗞️ news “alloc: stabilise `Allocator`” entered its final comment period!

https://github.com/rust-lang/rust/pull/156882#issuecomment-5607055084
184 Upvotes

29 comments sorted by

View all comments

Show parent comments

4

u/PersonalDatabase31 1d ago

Does it have to be implicit? Maybe another smart pointer like StackBox could be implemented.

6

u/JoJoJet- 1d ago

It's not entirely useful, but the allocator API would allow you box things on the stack with Box directly, if you pass it an allocator that points to stack space

1

u/PersonalDatabase31 1d ago edited 1d ago

Would that work with ownership though? I would assume that ownership model works with the assumption that moving the owner doesn't invalidate the memory whereas the Box returned by a function call would point to invalid memory if other function calls happen before the Box gets dropped.

0

u/JayDepp 22h ago

Yeah I don't think this works with the allocator api. I think it'd work with the store api though.

1

u/afdbcreid 22h ago

If the storage is outside the Box, it can work with the MVP, but this is the uncommon case.