As an exercise, I'm trying to create something similar to std::hive (a.k.a. a colony) from C++26 in Rust as a near absolute beginner in Rust, and using language features and the Standard library as much as possible.
In order to achieve the complexity requirements for insertion, deletion, and iteration, you need
>a linked list of all memory blocks allocated for the colony
>a linked list of nodes from the first list that point to memory blocks with unused elements
>a struct that tells us how to find the corresponding nodes in both lists (and an index into that block)
>a push function that returns objects of that struct
>a pop function that consumes objects of that struct
For example, in C++,
// Block class template defined above
template<typename T> class ItemHandle {
std::optional<std::list<std::list<Block<T>>::iterator>::iterator> opt_it_erased_block;
std::list<Block<T>>::iterator it_block;
std::size_t index;
};
template<typename T> class Colony {
// ... other fields ...
std::list<Block<T>> blocks;
std::list<std::list<Block<T>>::iterator> erased_blocks;

public:
// constructors/etc. ...

ItemHandle<T> push(const &T);
T pop(const &ItemHandle<T> h);
};

In Rust, the equivalent of std::list<T>::iterator here would be std::collections::linked_list::CursorMut<'a, T>, but because of the borrow checker, if you try to translate the above code directly
>can't give the erased-block list a real lifetime without requiring T: 'static (because the lifetime would be 'self, if it existed)
>can't return ItemHandle from push more than once, because fn push<'a>(&mut self, t: T) -> ItemHandle<'a,T> will require that the lifetime of &mut self outlive 'a
I've tried several ways to use unsafe code to get around these issues, but they all got unruly and error prone very fast, so I'm wondering if there is a technique I don't know about to this (without creating my own linked list).