feat: add AnyNodeTypes type (#9034)

This commit is contained in:
Aurélien
2024-06-24 11:34:43 +02:00
committed by GitHub
parent 8f2522eff9
commit 3c595f7d1d

View File

@ -26,6 +26,32 @@ pub trait NodeTypes: Send + Sync + Unpin + 'static {
type Engine: EngineTypes;
}
/// A [`NodeTypes`] type builder
#[derive(Default, Debug)]
pub struct AnyNodeTypes<P = (), E = ()>(PhantomData<P>, PhantomData<E>);
impl<P, E> AnyNodeTypes<P, E> {
/// Sets the `Primitives` associated type.
pub const fn primitives<T>(self) -> AnyNodeTypes<T, E> {
AnyNodeTypes::<T, E>(PhantomData::<T>, PhantomData::<E>)
}
/// Sets the `Engine` associated type.
pub const fn engine<T>(self) -> AnyNodeTypes<P, T> {
AnyNodeTypes::<P, T>(PhantomData::<P>, PhantomData::<T>)
}
}
impl<P, E> NodeTypes for AnyNodeTypes<P, E>
where
P: NodePrimitives + Send + Sync + Unpin + 'static,
E: EngineTypes + Send + Sync + Unpin + 'static,
{
type Primitives = P;
type Engine = E;
}
/// A helper trait that is downstream of the [`NodeTypes`] trait and adds stateful components to the
/// node.
///