Skip to content

Commit

Permalink
Add new() implementation for phantom data actors for creation
Browse files Browse the repository at this point in the history
  • Loading branch information
slawlor committed Feb 11, 2024
1 parent 935beac commit 8a79ce0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ractor_actors/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
25 changes: 23 additions & 2 deletions ractor_actors/src/net/tcp/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<R> {
pub struct Listener<R>
where
R: SessionAcceptor,
{
_r: PhantomData<R>,
}

impl<R> Default for Listener<R>
where
R: SessionAcceptor,
{
fn default() -> Self {
Self::new()
}
}

impl<R> Listener<R>
where
R: SessionAcceptor,
{
/// Create a new TCP Listener actor
pub fn new() -> Self {
Self { _r: PhantomData }
}
}

/// The Node listener's state
pub struct ListenerState<R>
where
Expand Down
20 changes: 19 additions & 1 deletion ractor_actors/src/net/tcp/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,32 @@ where
}

/// A tcp-session management actor
#[derive(Default)]
pub struct TcpSession<R>
where
R: FrameReceiver,
{
_r: PhantomData<R>,
}

impl<R> Default for TcpSession<R>
where
R: FrameReceiver,
{
fn default() -> Self {
Self::new()
}
}

impl<R> TcpSession<R>
where
R: FrameReceiver,
{
/// Create a new TcpSession actor instance
pub fn new() -> Self {
Self { _r: PhantomData }
}
}

#[ractor::async_trait]
impl<R> Actor for TcpSession<R>
where
Expand Down
1 change: 1 addition & 0 deletions ractor_actors/src/time/cron/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
}
Expand Down

0 comments on commit 8a79ce0

Please sign in to comment.