From bc02e19441380abf2cc4cdba2b8700b026420b32 Mon Sep 17 00:00:00 2001 From: Possseidon Date: Sat, 14 Oct 2023 14:57:55 +0200 Subject: [PATCH] `Bot::register` now also supports passing an `Arc` directly (#75) --- tranquil/src/bot.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tranquil/src/bot.rs b/tranquil/src/bot.rs index 29ce4cc..c13b72f 100644 --- a/tranquil/src/bot.rs +++ b/tranquil/src/bot.rs @@ -74,6 +74,22 @@ impl Default for Bot { } } +pub trait IntoArcModule { + fn into_arc_module(self) -> Arc; +} + +impl IntoArcModule for T { + fn into_arc_module(self) -> Arc { + Arc::new(self) + } +} + +impl IntoArcModule for Arc { + fn into_arc_module(self) -> Arc { + self + } +} + impl Bot { pub fn new() -> Self { Default::default() @@ -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 }