From 8a79ce0ad0bad182b8a9d29786b937fa0c49e612 Mon Sep 17 00:00:00 2001 From: Sean Lawlor Date: Sat, 10 Feb 2024 20:24:07 -0500 Subject: [PATCH] Add new() implementation for phantom data actors for creation --- ractor_actors/Cargo.toml | 2 +- ractor_actors/src/net/tcp/listener.rs | 25 +++++++++++++++++++++++-- ractor_actors/src/net/tcp/session.rs | 20 +++++++++++++++++++- ractor_actors/src/time/cron/mod.rs | 1 + 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/ractor_actors/Cargo.toml b/ractor_actors/Cargo.toml index 1907615..8fcbf58 100644 --- a/ractor_actors/Cargo.toml +++ b/ractor_actors/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ractor_actors" -version = "0.2.0" +version = "0.3.0" authors = ["Sean Lawlor"] description = "Helpful actors built with Ractor" documentation = "https://docs.rs/ractor_actors" diff --git a/ractor_actors/src/net/tcp/listener.rs b/ractor_actors/src/net/tcp/listener.rs index 4a85963..b1c17ea 100644 --- a/ractor_actors/src/net/tcp/listener.rs +++ b/ractor_actors/src/net/tcp/listener.rs @@ -14,11 +14,32 @@ use tokio::net::TcpListener; use super::{IncomingEncryptionMode, SessionAcceptor}; /// A Tcp Socket [Listener] responsible for accepting new connections. -#[derive(Default)] -pub struct Listener { +pub struct Listener +where + R: SessionAcceptor, +{ _r: PhantomData, } +impl Default for Listener +where + R: SessionAcceptor, +{ + fn default() -> Self { + Self::new() + } +} + +impl Listener +where + R: SessionAcceptor, +{ + /// Create a new TCP Listener actor + pub fn new() -> Self { + Self { _r: PhantomData } + } +} + /// The Node listener's state pub struct ListenerState where diff --git a/ractor_actors/src/net/tcp/session.rs b/ractor_actors/src/net/tcp/session.rs index 1cee745..a6da7f2 100644 --- a/ractor_actors/src/net/tcp/session.rs +++ b/ractor_actors/src/net/tcp/session.rs @@ -45,7 +45,6 @@ where } /// A tcp-session management actor -#[derive(Default)] pub struct TcpSession where R: FrameReceiver, @@ -53,6 +52,25 @@ where _r: PhantomData, } +impl Default for TcpSession +where + R: FrameReceiver, +{ + fn default() -> Self { + Self::new() + } +} + +impl TcpSession +where + R: FrameReceiver, +{ + /// Create a new TcpSession actor instance + pub fn new() -> Self { + Self { _r: PhantomData } + } +} + #[ractor::async_trait] impl Actor for TcpSession where diff --git a/ractor_actors/src/time/cron/mod.rs b/ractor_actors/src/time/cron/mod.rs index d75f910..dc93b17 100644 --- a/ractor_actors/src/time/cron/mod.rs +++ b/ractor_actors/src/time/cron/mod.rs @@ -309,6 +309,7 @@ mod tests { fn id<'a>(&self) -> &'a str { "bad_job" } + #[allow(clippy::diverging_sub_expression)] async fn work(&mut self) -> Result<(), ActorProcessingErr> { panic!("Boom!"); }