use crate::network::NetworkPlugin;
pub struct ClientBuilder<T> {
plugins: Vec<Box<dyn NetworkPlugin>>,
_phantom: std::marker::PhantomData<T>,
}
impl<T> Default for ClientBuilder<T>
where
T: BuildableClient,
{
fn default() -> Self {
Self::new()
}
}
impl<T> ClientBuilder<T>
where
T: BuildableClient,
{
pub fn new() -> Self {
Self {
plugins: Vec::new(),
_phantom: std::marker::PhantomData,
}
}
pub fn with_plugin(mut self, plugin: impl NetworkPlugin + 'static) -> Self {
self.plugins.push(Box::new(plugin));
self
}
pub fn build(self) -> T {
T::build_from_plugins(self.plugins)
}
}
pub trait BuildableClient {
fn build_from_plugins(plugins: Vec<Box<dyn NetworkPlugin>>) -> Self;
}