Skip to content

Commit

Permalink
[nakago-ws] Bugfix: Type Parameters (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkonkle authored Sep 11, 2024
1 parent ce523d0 commit b7af48d
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions nakago_ws/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,22 @@ impl<Session: Default + Send + Sync + Clone + Any> Controller<Session> {

/// Provide a new WebSocket Event Controller
#[derive(Default, new)]
pub struct Provide<U: Any> {
connections_tag: Option<&'static Tag<Connections<U>>>,
handler_tag: Option<&'static Tag<Box<dyn Handler<U>>>>,
pub struct Provide<Session: Any> {
connections_tag: Option<&'static Tag<Connections<Session>>>,
handler_tag: Option<&'static Tag<Box<dyn Handler<Session>>>>,
}

impl<U: Any> Provide<U> {
impl<Session: Any> Provide<Session> {
/// Set a Tag for the Connections instance this Provider requires
pub fn with_connections_tag(self, connections_tag: &'static Tag<Connections<U>>) -> Self {
pub fn with_connections_tag(self, connections_tag: &'static Tag<Connections<Session>>) -> Self {
Self {
connections_tag: Some(connections_tag),
..self
}
}

/// Set a Tag for the Handler instance this Provider requires
pub fn with_handler_tag(self, handler_tag: &'static Tag<Box<dyn Handler<U>>>) -> Self {
pub fn with_handler_tag(self, handler_tag: &'static Tag<Box<dyn Handler<Session>>>) -> Self {
Self {
handler_tag: Some(handler_tag),
..self
Expand All @@ -128,21 +128,21 @@ impl<U: Any> Provide<U> {

#[Provider]
#[async_trait]
impl<U> Provider<Controller<U>> for Provide<U>
impl<Session> Provider<Controller<Session>> for Provide<Session>
where
U: Send + Sync + Any,
Session: Send + Sync + Any,
{
async fn provide(self: Arc<Self>, i: Inject) -> provider::Result<Arc<Controller<U>>> {
async fn provide(self: Arc<Self>, i: Inject) -> provider::Result<Arc<Controller<Session>>> {
let connections = if let Some(tag) = self.connections_tag {
i.get_tag(tag).await?
} else {
i.get::<Connections<U>>().await?
i.get::<Connections<Session>>().await?
};

let handler = if let Some(tag) = self.handler_tag {
i.get_tag(tag).await?
} else {
i.get::<Box<dyn Handler<U>>>().await?
i.get::<Box<dyn Handler<Session>>>().await?
};

Ok(Arc::new(Controller::new(connections, handler)))
Expand Down

0 comments on commit b7af48d

Please sign in to comment.