Julio Biason
1 year ago
5 changed files with 500 additions and 0 deletions
@ -0,0 +1,375 @@ |
|||||||
|
# This file is automatically @generated by Cargo. |
||||||
|
# It is not intended for manual editing. |
||||||
|
version = 3 |
||||||
|
|
||||||
|
[[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 2.0.28", |
||||||
|
] |
||||||
|
|
||||||
|
[[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 = "const-random" |
||||||
|
version = "0.1.15" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "368a7a772ead6ce7e1de82bfb04c485f3db8ec744f72925af5735e29a22cc18e" |
||||||
|
dependencies = [ |
||||||
|
"const-random-macro", |
||||||
|
"proc-macro-hack", |
||||||
|
] |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "const-random-macro" |
||||||
|
version = "0.1.15" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "9d7d6ab3c3a2282db210df5f02c4dab6e0a7057af0fb7ebd4070f30fe05c0ddb" |
||||||
|
dependencies = [ |
||||||
|
"getrandom", |
||||||
|
"once_cell", |
||||||
|
"proc-macro-hack", |
||||||
|
"tiny-keccak", |
||||||
|
] |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "crunchy" |
||||||
|
version = "0.2.2" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "derive-syn-parse" |
||||||
|
version = "0.1.5" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "e79116f119dd1dba1abf1f3405f03b9b0e79a27a3883864bfebded8a3dc768cd" |
||||||
|
dependencies = [ |
||||||
|
"proc-macro2", |
||||||
|
"quote", |
||||||
|
"syn 1.0.109", |
||||||
|
] |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "getrandom" |
||||||
|
version = "0.2.10" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" |
||||||
|
dependencies = [ |
||||||
|
"cfg-if", |
||||||
|
"libc", |
||||||
|
"wasi", |
||||||
|
] |
||||||
|
|
||||||
|
[[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 = "macro_magic" |
||||||
|
version = "0.4.2" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "aee866bfee30d2d7e83835a4574aad5b45adba4cc807f2a3bbba974e5d4383c9" |
||||||
|
dependencies = [ |
||||||
|
"macro_magic_core", |
||||||
|
"macro_magic_macros", |
||||||
|
"quote", |
||||||
|
"syn 2.0.28", |
||||||
|
] |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "macro_magic_core" |
||||||
|
version = "0.4.2" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "7e766a20fd9c72bab3e1e64ed63f36bd08410e75803813df210d1ce297d7ad00" |
||||||
|
dependencies = [ |
||||||
|
"const-random", |
||||||
|
"derive-syn-parse", |
||||||
|
"macro_magic_core_macros", |
||||||
|
"proc-macro2", |
||||||
|
"quote", |
||||||
|
"syn 2.0.28", |
||||||
|
] |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "macro_magic_core_macros" |
||||||
|
version = "0.4.2" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "c12469fc165526520dff2807c2975310ab47cf7190a45b99b49a7dc8befab17b" |
||||||
|
dependencies = [ |
||||||
|
"proc-macro2", |
||||||
|
"quote", |
||||||
|
"syn 2.0.28", |
||||||
|
] |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "macro_magic_macros" |
||||||
|
version = "0.4.2" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "b8fb85ec1620619edf2984a7693497d4ec88a9665d8b87e942856884c92dbf2a" |
||||||
|
dependencies = [ |
||||||
|
"macro_magic_core", |
||||||
|
"quote", |
||||||
|
"syn 2.0.28", |
||||||
|
] |
||||||
|
|
||||||
|
[[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 = "once_cell" |
||||||
|
version = "1.18.0" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "pin-project-lite" |
||||||
|
version = "0.2.12" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "12cc1b0bf1727a77a54b6654e7b5f1af8604923edc8b81885f8ec92f9e3f0a05" |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "ppv-lite86" |
||||||
|
version = "0.2.17" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "proc-macro-hack" |
||||||
|
version = "0.5.20+deprecated" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" |
||||||
|
|
||||||
|
[[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 = "rand" |
||||||
|
version = "0.8.5" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" |
||||||
|
dependencies = [ |
||||||
|
"libc", |
||||||
|
"rand_chacha", |
||||||
|
"rand_core", |
||||||
|
] |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "rand_chacha" |
||||||
|
version = "0.3.1" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" |
||||||
|
dependencies = [ |
||||||
|
"ppv-lite86", |
||||||
|
"rand_core", |
||||||
|
] |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "rand_core" |
||||||
|
version = "0.6.4" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" |
||||||
|
dependencies = [ |
||||||
|
"getrandom", |
||||||
|
] |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "rustc-demangle" |
||||||
|
version = "0.1.23" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "supertrait" |
||||||
|
version = "0.1.0" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "7b17916ac8af1d88f25976f22aa63e359aa45010fc8e0d8c4b8a1f723e173ce9" |
||||||
|
dependencies = [ |
||||||
|
"macro_magic", |
||||||
|
"supertrait-macros", |
||||||
|
] |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "supertrait-macros" |
||||||
|
version = "0.1.0" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "30fb6cf8173f79cebf072754a5ce9cc4bdf3a952ecfd7bdaa6103bf0a84c9f03" |
||||||
|
dependencies = [ |
||||||
|
"macro_magic", |
||||||
|
"proc-macro2", |
||||||
|
"quote", |
||||||
|
"rand", |
||||||
|
"syn 2.0.28", |
||||||
|
] |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "syn" |
||||||
|
version = "1.0.109" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" |
||||||
|
dependencies = [ |
||||||
|
"proc-macro2", |
||||||
|
"quote", |
||||||
|
"unicode-ident", |
||||||
|
] |
||||||
|
|
||||||
|
[[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 = "tiny-keccak" |
||||||
|
version = "2.0.2" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" |
||||||
|
dependencies = [ |
||||||
|
"crunchy", |
||||||
|
] |
||||||
|
|
||||||
|
[[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 2.0.28", |
||||||
|
] |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "transformertest" |
||||||
|
version = "0.1.0" |
||||||
|
dependencies = [ |
||||||
|
"async-trait", |
||||||
|
"supertrait", |
||||||
|
"tokio", |
||||||
|
] |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "unicode-ident" |
||||||
|
version = "1.0.11" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "wasi" |
||||||
|
version = "0.11.0+wasi-snapshot-preview1" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" |
@ -0,0 +1,11 @@ |
|||||||
|
[package] |
||||||
|
name = "transformertest" |
||||||
|
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" |
||||||
|
supertrait = "0.1.0" |
||||||
|
tokio = { version = "1.31.0", features = ["rt", "macros", "fs", "io-util", "sync"] } |
@ -0,0 +1,3 @@ |
|||||||
|
# TransformerTest |
||||||
|
|
||||||
|
Trying a different approach to Actors: Transformers. |
@ -0,0 +1,47 @@ |
|||||||
|
use std::path::PathBuf; |
||||||
|
|
||||||
|
use transformer::Generator; |
||||||
|
// use transformer::Processor;
|
||||||
|
use transformer::Source; |
||||||
|
// use transformer::Transformer;
|
||||||
|
|
||||||
|
mod transformer; |
||||||
|
|
||||||
|
struct Input {} |
||||||
|
#[async_trait::async_trait] |
||||||
|
impl Generator for Input { |
||||||
|
type Output = PathBuf; |
||||||
|
|
||||||
|
async fn next(&self) -> Option<PathBuf> {} |
||||||
|
} |
||||||
|
|
||||||
|
// struct PathBufToString {}
|
||||||
|
// impl Processor for PathBufToString {
|
||||||
|
// type Input = PathBuf;
|
||||||
|
// type Output = String;
|
||||||
|
|
||||||
|
// fn transform(&self, data: PathBuf) -> String {
|
||||||
|
// data.to_string_lossy().to_string()
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// struct Printer {}
|
||||||
|
// impl Processor for Printer {
|
||||||
|
// type Input = String;
|
||||||
|
// type Output = (); // this is a sync
|
||||||
|
|
||||||
|
// fn transform(&self, data: String) -> () {
|
||||||
|
// println!("{:?}", data);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
fn main() { |
||||||
|
let gen = Source::new(Input {}); |
||||||
|
// let pbts = Transformer::new(PathBufToString {});
|
||||||
|
// let printer = Transformer::new(Printer {});
|
||||||
|
|
||||||
|
// gen.chain(pbts);
|
||||||
|
// pbts.chain(printer);
|
||||||
|
|
||||||
|
// run(printer, pbts, gen);
|
||||||
|
} |
@ -0,0 +1,64 @@ |
|||||||
|
//! Transformers framework.
|
||||||
|
|
||||||
|
use tokio::task::JoinHandle; |
||||||
|
|
||||||
|
#[async_trait::async_trait] |
||||||
|
pub trait Generator { |
||||||
|
type Output; |
||||||
|
|
||||||
|
async fn next(&self) -> Option<Self::Output>; |
||||||
|
} |
||||||
|
|
||||||
|
pub trait Processor { |
||||||
|
type Input; |
||||||
|
type Output; |
||||||
|
|
||||||
|
fn transform(&self, data: Self::Input) -> Self::Output; |
||||||
|
} |
||||||
|
|
||||||
|
pub struct Transformer<P: Processor> { |
||||||
|
chain: Vec<Transformer<dyn Processor<Input = P::Output>>>, |
||||||
|
processor: P, |
||||||
|
} |
||||||
|
|
||||||
|
pub struct Source<G> where G: Generator { |
||||||
|
chain: Vec<Transformer<dyn Processor<Input = G::Output>>>, |
||||||
|
generator: G, |
||||||
|
} |
||||||
|
|
||||||
|
impl<G: Generator> Source<G> { |
||||||
|
pub fn new(gen: G) -> Self { |
||||||
|
Self { |
||||||
|
chain: vec![], |
||||||
|
generator: gen, |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
pub fn chain(&mut self, next: Transformer<G::Output> ) { |
||||||
|
self.chain.push(next); |
||||||
|
} |
||||||
|
|
||||||
|
// pub async fn spawn(&self) -> JoinHandle<()> {
|
||||||
|
// tokio::spawn(async {
|
||||||
|
// while let Some(data) = gen.next().await {
|
||||||
|
// for next in self.chain {
|
||||||
|
// next.send(data).await.unwrap();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
// impl<P: Processor> Transformer<P> {
|
||||||
|
// pub fn new(proc: P) -> Self {
|
||||||
|
// Self {
|
||||||
|
// chain: vec![],
|
||||||
|
// processor: proc
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// pub fn chain(&mut self, next: Transformer<P::Output>) {
|
||||||
|
// self.chain.push(next);
|
||||||
|
// }
|
||||||
|
// }
|
Loading…
Reference in new issue