diff --git a/actorstest/Cargo.lock b/actorstest/Cargo.lock new file mode 100644 index 0000000..6c9604e --- /dev/null +++ b/actorstest/Cargo.lock @@ -0,0 +1,179 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "actorstest" +version = "0.1.0" +dependencies = [ + "async-trait", + "tokio", +] + +[[package]] +name = "addr2line" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4fa78e18c64fce05e902adecd7a5eed15a5e0a3439f7b0e169f0252214865e3" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async-trait" +version = "0.1.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "backtrace" +version = "0.3.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4319208da049c43661739c5fade2ba182f09d1dc2299b32298d3a31692b17e12" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bytes" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" + +[[package]] +name = "cc" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "305fe645edc1442a0fa8b6726ba61d422798d37a52e12eaecf4b022ebbb88f01" +dependencies = [ + "libc", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "gimli" +version = "0.27.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e" + +[[package]] +name = "libc" +version = "0.2.147" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "miniz_oxide" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +dependencies = [ + "adler", +] + +[[package]] +name = "object" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bda667d9f2b5051b8833f59f3bf748b28ef54f850f4fcb389a252aa383866d1" +dependencies = [ + "memchr", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12cc1b0bf1727a77a54b6654e7b5f1af8604923edc8b81885f8ec92f9e3f0a05" + +[[package]] +name = "proc-macro2" +version = "1.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" + +[[package]] +name = "syn" +version = "2.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04361975b3f5e348b2189d8dc55bc942f278b2d482a6a0365de5bdd62d351567" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40de3a2ba249dcb097e01be5e67a5ff53cf250397715a071a81543e8a832a920" +dependencies = [ + "backtrace", + "bytes", + "pin-project-lite", + "tokio-macros", +] + +[[package]] +name = "tokio-macros" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "unicode-ident" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" diff --git a/actorstest/Cargo.toml b/actorstest/Cargo.toml new file mode 100644 index 0000000..8755f5a --- /dev/null +++ b/actorstest/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "actorstest" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +async-trait = "0.1.73" +tokio = { version = "1.31.0", features = ["rt", "macros", "fs", "io-util", "sync"] } diff --git a/actorstest/README.md b/actorstest/README.md new file mode 100644 index 0000000..735b2b7 --- /dev/null +++ b/actorstest/README.md @@ -0,0 +1,3 @@ +# ActorsTest + +Testing an interface for Actors. diff --git a/actorstest/src/actor.rs b/actorstest/src/actor.rs new file mode 100644 index 0000000..99925f3 --- /dev/null +++ b/actorstest/src/actor.rs @@ -0,0 +1,13 @@ +//! The definition of an actor. + +use tokio::sync::mpsc; +use tokio::task; + +#[async_trait::async_trait] +pub trait Actor { + /// The type of value that the actor will receive. + type Input: Send; + + /// Actor execution. + async fn process(&self) -> (task::JoinHandle<()>, mpsc::Sender); +} diff --git a/actorstest/src/actor_1.rs b/actorstest/src/actor_1.rs new file mode 100644 index 0000000..a7c4ba7 --- /dev/null +++ b/actorstest/src/actor_1.rs @@ -0,0 +1,29 @@ +//! Actor 1. + +use tokio::{task, sync::mpsc}; + +use crate::actor::Actor; + +pub struct Actor1 {} + +impl Actor1 { + pub fn new() -> Self { + Self {} + } +} + +#[async_trait::async_trait] +impl Actor for Actor1 { + type Input = (); + + async fn process(&self) -> (task::JoinHandle<()>, mpsc::Sender) { + let (tx, mut rx) = mpsc::channel::(10); + let task = task::spawn(async move { + while let Some(data) = rx.recv().await { + println!("{:?}", data); + } + }); + + (task, tx) + } +} diff --git a/actorstest/src/main.rs b/actorstest/src/main.rs new file mode 100644 index 0000000..f794134 --- /dev/null +++ b/actorstest/src/main.rs @@ -0,0 +1,11 @@ +use actor::Actor; + +mod actor; + +mod actor_1; + +#[tokio::main(flavor = "current_thread")] +async fn main() { + let one = actor_1::Actor1::new(); + let (worker1, channel1) = one.process().await; +}