|
|
|
|
|
by iudqnolq
1164 days ago
|
|
> That just restricts A to implement Allocator trait and will allow to pass any instance of Allocator when calling methods of MyVect. No, that kind of rust generic requires monomorphization rather than dynamic dispatch. Any given Vec must have a specific A, just like it must have a specific T. > To make this compile-time safe in Rust a typical approach is to embed the Allocator reference in MyVect Yeah, that was implied by the "...". It won't compile otherwise, generics have to be used (including by PhantomData). But I understand the problem better now. You're right, there's no good way in the type system to specify "you must always provide the same instance of this allocator when calling any method on this vec". (I'm ignoring branding because I think it's not practically convenient). |
|