vhdl: add AllocInto trait
Add the `AllocInto` trait which behaves similarly to `Alloc`, but allows
for the allocated references' lifetimes not to be bound to `self`. This
paves the way for context objects which delegate allocation to an Arena.
@@ -10,6 +10,23 @@ pub trait Alloc<T> {
fn alloc(&self, value: T) -> &mut T;
}
+/// Allocates objects into a remote arena.
+///
+/// In contrast to `Alloc`, the lifetime of the references returned by this
+/// trait are not bound to the trait itself. Rather, the lifetime is a parameter
+/// of the trait itself. This allows context objects to be created that hold a
+/// reference to an arena, and allow for direct allocation into that arena.
+pub trait AllocInto<'t, T> {
+ /// Allocate an object of type `T`.
+ fn alloc(&self, value: T) -> &'t mut T;
+}
+
+impl<'t, T> AllocInto<'t, T> for &'t Alloc<T> {
+ fn alloc(&self, value: T) -> &'t mut T {
+ Alloc::alloc(*self, value)
+ }
+}
+
#[macro_export]
macro_rules! make_arenas {
($(#[$arena_attr:meta])* pub struct $arena_name:ident { $($name:ident: $type:ty,)* }) => (
