3 ms·
1. You can do anything you want in Rust, you can make your own collections do whatever you want at any time. 2. These changes are about two things, 2a. the fi
by steveklabnik 4y ago
1. You can do anything you want in Rust, you can make your own collections do whatever you want at any time.
2. These changes are about two things,
2a. the first of which is a trait that represents the concept of an allocator, in case users' code would like to be generic over ones that exist in the ecosystem. You can of course still paper over this yourself but the whole point of a vocabulary trait is so that you don't have to do all the work yourself.
2b. the second of which is how the collections in the standard library are customized by allocators.
So, in your own code, absolutely you could do that if you wanted to. With this proposal, and trying to do that with a standard library provided data structure? I'm not an expert on the API that it gives, so I can't really speak to its viability here. I would imagine it's not super simple, given what I do know.
- throwawaymaths 4y agosorry, I should have been clear: I meant with a standard lib provided data structure. Thanks!
- monocasa 4y agoYes, the data structures in std are parameterized over the allocator, with Global as the default allocator if not specified. https://doc.rust-lang.org/std/vec/struct.Vec.html https://doc.rust-lang.org/std/vec/struct.Vec.html
- throwawaymaths 4y agoThe point is, they are parametrized over a type, not an instance. By contrast, types in zig that are variadic by allocator are (typically) parametrized over instance.