Skip to content

Commit

Permalink
Bot::register now also supports passing an Arc directly (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
Possseidon authored Oct 14, 2023
1 parent b592fc1 commit bc02e19
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions tranquil/src/bot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ impl Default for Bot {
}
}

pub trait IntoArcModule {
fn into_arc_module(self) -> Arc<dyn Module>;
}

impl<T: Module + 'static> IntoArcModule for T {
fn into_arc_module(self) -> Arc<dyn Module> {
Arc::new(self)
}
}

impl<T: Module + 'static> IntoArcModule for Arc<T> {
fn into_arc_module(self) -> Arc<dyn Module> {
self
}
}

impl Bot {
pub fn new() -> Self {
Default::default()
Expand All @@ -87,8 +103,8 @@ impl Bot {
self
}

pub fn register(mut self, module: impl Module + 'static) -> Self {
self.modules.push(Arc::new(module));
pub fn register(mut self, module: impl IntoArcModule) -> Self {
self.modules.push(module.into_arc_module());
self
}

Expand Down

0 comments on commit bc02e19

Please sign in to comment.