Skip to content

Commit

Permalink
Add default factory
Browse files Browse the repository at this point in the history
  • Loading branch information
paulgb committed May 5, 2024
1 parent 868373f commit efef543
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion stateroom/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
//! }
//! }

use std::sync::Arc;
use std::{convert::Infallible, sync::Arc};

pub use client_id::ClientId;
pub use message_recipient::MessageRecipient;
Expand Down Expand Up @@ -137,3 +137,20 @@ pub trait StateroomServiceFactory: Send + Sync + 'static {
context: Arc<impl StateroomContext>,
) -> Result<Self::Service, Self::Error>;
}

pub struct DefaultStateroomFactory<T: StateroomService + Default> {
_marker: std::marker::PhantomData<T>,
}

impl<T: StateroomService + Default> StateroomServiceFactory for DefaultStateroomFactory<T> {
type Service = T;
type Error = Infallible;

fn build(
&self,
_: &str,
_: Arc<impl StateroomContext>,
) -> Result<Self::Service, Self::Error> {
Ok(T::default())
}
}

0 comments on commit efef543

Please sign in to comment.