diff --git a/.gitignore b/.gitignore index 0017133..e3a0ab0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ -/target local-test-suit .idea/ Cargo.lock +**/Cargo.lock target/ \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 13566b8..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index 2bd63b7..0000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 6ad44a2..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/native-channel.iml b/.idea/native-channel.iml deleted file mode 100644 index 4fdb4ea..0000000 --- a/.idea/native-channel.iml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock deleted file mode 100644 index 1136bfc..0000000 --- a/Cargo.lock +++ /dev/null @@ -1,768 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "anyhow" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "224afbd727c3d6e4b90103ece64b8d1b67fbb1973b1046c2281eed3f3803f800" - -[[package]] -name = "async-channel" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf46fee83e5ccffc220104713af3292ff9bc7c64c7de289f66dae8e38d826833" -dependencies = [ - "concurrent-queue", - "event-listener", - "futures-core", -] - -[[package]] -name = "async-trait" -version = "0.1.64" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cd7fce9ba8c3c042128ce72d8b2ddbf3a05747efb67ea0313c635e10bda47a2" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "bytes" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "concurrent-queue" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c278839b831783b70278b14df4d45e1beb1aad306c07bb796637de9a0e323e8e" -dependencies = [ - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "event-listener" -version = "2.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" - -[[package]] -name = "futures" -version = "0.3.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "531ac96c6ff5fd7c62263c5e3c67a603af4fcaee2e1a0ae5565ba3a11e69e549" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "164713a5a0dcc3e7b4b1ed7d3b433cabc18025386f9339346e8daf15963cf7ac" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86d7a0c1aa76363dac491de0ee99faf6941128376f1cf96f07db7603b7de69dd" - -[[package]] -name = "futures-executor" -version = "0.3.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1997dd9df74cdac935c76252744c1ed5794fac083242ea4fe77ef3ed60ba0f83" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89d422fa3cbe3b40dca574ab087abb5bc98258ea57eea3fd6f1fa7162c778b91" - -[[package]] -name = "futures-macro" -version = "0.3.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3eb14ed937631bd8b8b8977f2c198443447a8355b6e3ca599f38c975e5a963b6" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec93083a4aecafb2a80a885c9de1f0ccae9dbd32c2bb54b0c3a65690e0b8d2f2" - -[[package]] -name = "futures-task" -version = "0.3.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd65540d33b37b16542a0438c12e6aeead10d4ac5d05bd3f805b8f35ab592879" - -[[package]] -name = "futures-util" -version = "0.3.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ef6b17e481503ec85211fed8f39d1970f128935ca1f814cd32ac4a6842e84ab" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "hermit-abi" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" -dependencies = [ - "libc", -] - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - -[[package]] -name = "libc" -version = "0.2.139" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" - -[[package]] -name = "libloading" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" -dependencies = [ - "cfg-if", - "winapi", -] - -[[package]] -name = "lock_api" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "log" -version = "0.4.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "memchr" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" - -[[package]] -name = "minimal-lexical" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" - -[[package]] -name = "mio" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9" -dependencies = [ - "libc", - "log", - "wasi", - "windows-sys 0.45.0", -] - -[[package]] -name = "modular-native" -version = "0.1.0" -dependencies = [ - "bytes", - "futures", - "modular-rs 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "modular-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot", - "tokio", - "tower", -] - -[[package]] -name = "modular-rs" -version = "0.1.0" -dependencies = [ - "anyhow", - "async-channel", - "async-trait", - "bytes", - "futures", - "futures-util", - "nom", - "parking_lot", - "thiserror", - "tokio", - "tower", - "tracing", - "tracing-subscriber", -] - -[[package]] -name = "modular-rs" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a47e584ec92df3832fa80e54ab3a1d5262ed1fe33b4c07b7ef533dbc5fca9964" -dependencies = [ - "anyhow", - "async-channel", - "async-trait", - "bytes", - "futures", - "futures-util", - "nom", - "parking_lot", - "thiserror", - "tokio", - "tower", - "tracing", - "tracing-subscriber", -] - -[[package]] -name = "modular-sys" -version = "0.1.0" -dependencies = [ - "anyhow", - "async-trait", - "bytes", - "futures-util", - "libloading", - "once_cell", - "parking_lot", - "tokio", - "tower", -] - -[[package]] -name = "modular-sys" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15a976e9320a5c57409a24ec38b3f9ecbe5ad25cc57c2d30d1ffc5d56ef6f7ca" - -[[package]] -name = "nom" -version = "7.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" -dependencies = [ - "memchr", - "minimal-lexical", -] - -[[package]] -name = "nu-ansi-term" -version = "0.46.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" -dependencies = [ - "overload", - "winapi", -] - -[[package]] -name = "num_cpus" -version = "1.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "once_cell" -version = "1.17.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" - -[[package]] -name = "overload" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" - -[[package]] -name = "parking_lot" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-sys 0.45.0", -] - -[[package]] -name = "pin-project" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad29a609b6bcd67fee905812e544992d216af9d755757c05ed2d0e15a74c6ecc" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.51" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "redox_syscall" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" -dependencies = [ - "bitflags", -] - -[[package]] -name = "scopeguard" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" - -[[package]] -name = "sharded-slab" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" -dependencies = [ - "lazy_static", -] - -[[package]] -name = "signal-hook-registry" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" -dependencies = [ - "libc", -] - -[[package]] -name = "slab" -version = "0.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" - -[[package]] -name = "socket2" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" -dependencies = [ - "libc", - "winapi", -] - -[[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 = "thiserror" -version = "1.0.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "thread_local" -version = "1.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" -dependencies = [ - "cfg-if", - "once_cell", -] - -[[package]] -name = "tokio" -version = "1.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8e00990ebabbe4c14c08aca901caed183ecd5c09562a12c824bb53d3c3fd3af" -dependencies = [ - "autocfg", - "bytes", - "libc", - "memchr", - "mio", - "num_cpus", - "parking_lot", - "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.42.0", -] - -[[package]] -name = "tokio-macros" -version = "1.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tower" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" -dependencies = [ - "futures-core", - "futures-util", - "pin-project", - "pin-project-lite", - "tower-layer", - "tower-service", - "tracing", -] - -[[package]] -name = "tower-layer" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" - -[[package]] -name = "tower-service" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" - -[[package]] -name = "tracing" -version = "0.1.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" -dependencies = [ - "cfg-if", - "log", - "pin-project-lite", - "tracing-attributes", - "tracing-core", -] - -[[package]] -name = "tracing-attributes" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tracing-core" -version = "0.1.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" -dependencies = [ - "once_cell", - "valuable", -] - -[[package]] -name = "tracing-log" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922" -dependencies = [ - "lazy_static", - "log", - "tracing-core", -] - -[[package]] -name = "tracing-subscriber" -version = "0.3.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6176eae26dd70d0c919749377897b54a9276bd7061339665dd68777926b5a70" -dependencies = [ - "nu-ansi-term", - "sharded-slab", - "smallvec", - "thread_local", - "tracing-core", - "tracing-log", -] - -[[package]] -name = "unicode-ident" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" - -[[package]] -name = "valuable" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "windows-sys" -version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows-sys" -version = "0.45.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-targets" -version = "0.42.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.42.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.42.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" - -[[package]] -name = "windows_i686_gnu" -version = "0.42.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" - -[[package]] -name = "windows_i686_msvc" -version = "0.42.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.42.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.42.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.42.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" diff --git a/Cargo.toml b/Cargo.toml index a05dec6..0c58ed4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,4 +3,5 @@ members = [ "modular", "modular-native", "modular-sys", + "modular-core" ] \ No newline at end of file diff --git a/modular-core/Cargo.toml b/modular-core/Cargo.toml new file mode 100644 index 0000000..547ed1d --- /dev/null +++ b/modular-core/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "modular-core" +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.68" +anyhow = "1.0.70" +bytes = "1.4.0" +futures = "0.3.28" +thiserror = "1.0.40" +tower = "0.4.13" \ No newline at end of file diff --git a/modular/src/core/error.rs b/modular-core/src/error.rs similarity index 71% rename from modular/src/core/error.rs rename to modular-core/src/error.rs index e4dc753..90522cb 100644 --- a/modular/src/core/error.rs +++ b/modular-core/src/error.rs @@ -15,3 +15,9 @@ pub struct CustomModuleError { pub enum SubscribeError { InvalidPattern(anyhow::Error), } + +#[derive(thiserror::Error, Debug)] +pub enum RegistryError { + #[error("module already exists")] + AlreadyExists, +} diff --git a/modular-core/src/lib.rs b/modular-core/src/lib.rs new file mode 100644 index 0000000..7d6985d --- /dev/null +++ b/modular-core/src/lib.rs @@ -0,0 +1,11 @@ +pub mod error; +pub mod modular; +pub mod module; +pub mod request; +pub mod response; + +pub mod modules { + pub use super::error::*; + pub use super::request::*; + pub use super::response::*; +} diff --git a/modular-core/src/modular.rs b/modular-core/src/modular.rs new file mode 100644 index 0000000..d11372e --- /dev/null +++ b/modular-core/src/modular.rs @@ -0,0 +1,38 @@ +use crate::module::Module; +use crate::modules::*; +use bytes::Bytes; +use futures::future::BoxFuture; +use futures::Sink; +use std::future::Future; +use tower::Service; + +pub type BoxModule = + Box>>>; + +pub trait Modular: Send + Sync { + type Stream: Send + 'static; + type Module; + + fn register_module(&self, name: &str, service: S) -> Result<(), RegistryError> + where + S: Service + 'static + Send + Sync, + S::Response: Into + Send + 'static, + S::Error: Into + Send + 'static, + S::Future: Future> + Send + Sync + 'static; + + fn subscribe( + &self, + topic: &str, + sink: Option, + ) -> Result + where + S: Sink<(String, Bytes), Error = Err> + Send + Sync + 'static; + + fn publish(&self, event: Request) + where + Request: Into>; + + fn get_module(&self, name: &str) -> Option; + + fn deregister_module(&self, name: &str); +} diff --git a/modular-core/src/module.rs b/modular-core/src/module.rs new file mode 100644 index 0000000..7fe2d32 --- /dev/null +++ b/modular-core/src/module.rs @@ -0,0 +1,13 @@ +use crate::modules::ModuleRequest; +use bytes::Bytes; +use std::future::Future; + +pub trait Module +where + Response: Send + 'static, + Request: Send, +{ + type Future: Future + Send + 'static; + + fn invoke(&self, req: ModuleRequest) -> Self::Future; +} diff --git a/modular/src/core/req.rs b/modular-core/src/request.rs similarity index 100% rename from modular/src/core/req.rs rename to modular-core/src/request.rs diff --git a/modular/src/core/response.rs b/modular-core/src/response.rs similarity index 100% rename from modular/src/core/response.rs rename to modular-core/src/response.rs diff --git a/modular-native/Cargo.toml b/modular-native/Cargo.toml index 201dacc..0b17c42 100644 --- a/modular-native/Cargo.toml +++ b/modular-native/Cargo.toml @@ -17,6 +17,8 @@ tower = "0.4" bytes = "1" futures = { version = "0.3", features = [ ] } +modular-core = {version = "0.1", path = "../modular-core"} + [target.'cfg(not(target_family = "wasm"))'.dependencies] tokio = { version = "1", features = [ "rt", "rt-multi-thread" ] } diff --git a/modular-native/src/lib.rs b/modular-native/src/lib.rs index 9cf11a7..def14b0 100644 --- a/modular-native/src/lib.rs +++ b/modular-native/src/lib.rs @@ -5,9 +5,9 @@ mod module; use crate::module::NativeCModule; use bytes::Bytes; use futures::Sink; -use modular_rs::core::error::{ModuleError, SubscribeError}; -use modular_rs::core::modules::{Module, ModuleRequest, RegistryError}; -use modular_rs::core::Modular; +use modular_core::modular::Modular; +use modular_core::module::Module; +use modular_core::modules::*; use modular_sys::*; use parking_lot::RwLock; use std::ffi::{CStr, CString}; @@ -40,7 +40,7 @@ macro_rules! cstr_to_str { pub struct NativeModular { tokio_runtime: Arc, - modular: Modular, + modular: modular_rs::core::Modular, } #[repr(C)] @@ -96,7 +96,7 @@ pub unsafe extern "system" fn __modular_create(threads: u32) -> *mut NativeModul .unwrap() }; - let modular = Modular::default(); + let modular = modular_rs::core::Modular::default(); Box::into_raw(Box::new(NativeModular { tokio_runtime: Arc::new(runtime), @@ -222,7 +222,7 @@ pub unsafe extern "system" fn __modular_events_subscribe( let handle = modular.tokio_runtime.handle(); let _guard = handle.enter(); - match modular.modular.subscribe(&topic, subscribe) { + match modular.modular.subscribe(&topic, Some(subscribe)) { Ok(_) => { *subscription = subscription_ref; @@ -246,7 +246,7 @@ pub unsafe extern "system" fn __modular_events_publish( let topic = cstr_to_str!(topic).expect("topic must not be null"); let bytes = Bytes::copy_from_slice(std::slice::from_raw_parts(buf.data, buf.len)); - modular.modular.publish_event(&topic, bytes) + modular.modular.publish(ModuleRequest::new(&topic, bytes)) } pub unsafe extern "system" fn __modular_events_unsubscribe(subscription: Obj) { @@ -287,7 +287,7 @@ pub unsafe extern "system" fn __modular_remove_module( name: *const c_char, ) { if let Some(v) = cstr_to_str!(name) { - modular.modular.remove_module(&v) + modular.modular.deregister_module(&v) } } @@ -304,7 +304,7 @@ pub unsafe extern "system" fn __modular_get_module_ref( #[derive(Clone)] pub struct RtModule { runtime: Weak, - module: Module, + module: modular_rs::core::modules::Module, } let name = cstr_to_str!(name).expect("name can't be empty"); @@ -350,12 +350,13 @@ pub unsafe extern "system" fn __modular_get_module_ref( task: Box::pin(async move { match module.invoke(ModuleRequest::new(&action, data)).await { Ok(response) => { - let buf = CBuf { - data: response.data.as_ptr(), - len: response.data.len(), - }; - - (callback.success)(callback.ptr, buf) + if let Ok(response) = response.await { + let buf = CBuf { + data: response.data.as_ptr(), + len: response.data.len(), + }; + (callback.success)(callback.ptr, buf) + } } Err(error) => match error { ModuleError::UnknownMethod => (callback.unknown_method)(callback.ptr), diff --git a/modular-native/src/module.rs b/modular-native/src/module.rs index 96b31e1..89c9feb 100644 --- a/modular-native/src/module.rs +++ b/modular-native/src/module.rs @@ -1,8 +1,7 @@ use crate::cstr_to_string; use crate::*; use bytes::Bytes; -use modular_rs::core::error::{CustomModuleError, ModuleError}; -use modular_rs::core::modules::{ModuleRequest, ModuleResponse}; +use modular_core::error::{CustomModuleError, ModuleError}; use modular_sys::*; use parking_lot::RwLock; use std::ffi::CString; diff --git a/modular-sys/Cargo.toml b/modular-sys/Cargo.toml index 6a01362..ed9a43c 100644 --- a/modular-sys/Cargo.toml +++ b/modular-sys/Cargo.toml @@ -9,10 +9,11 @@ license = "MIT OR Apache-2.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -libloading = { version = "0.7", optional = true } +libloading = { version = "0.8.0", optional = true } bytes = { version = "1", optional = true } tower = { version = "0.4", optional = true } async-trait = { version = "0.1", optional = true } +modular-core = {version = "0.1", path = "../modular-core"} futures-util = { version = "0.3", optional = true } anyhow = { version = "1", optional = true } parking_lot = { version = "0.12", optional = true, features = [ "send_guard" ] } diff --git a/modular-sys/src/core/mod.rs b/modular-sys/src/core/mod.rs index 3e5e170..3a6b43d 100644 --- a/modular-sys/src/core/mod.rs +++ b/modular-sys/src/core/mod.rs @@ -1,31 +1 @@ #![cfg(feature = "dll")] - -use crate::dll::LibraryError; -use bytes::Bytes; -use futures_util::future::BoxFuture; -use futures_util::stream::BoxStream; -use std::future::Future; - -pub type BoxModule = Box>>>; - -pub trait Modular: Send + Sync { - fn subscribe(&self, topic: &str) -> anyhow::Result>; - fn publish(&self, topic: &str, data: Bytes); - - fn register_module(&self, name: &str, service: S) - where - S: tower::Service<(String, Bytes), Response = Bytes, Error = LibraryError> - + 'static - + Send - + Sync, - S::Future: Send + Sync + 'static; - - fn get_module(&self, name: &str) -> Option; - fn deregister_module(&self, name: &str); -} - -pub trait Module { - type Future: Future> + Send + 'static; - - fn invoke(&self, method: &str, data: Bytes) -> Self::Future; -} diff --git a/modular-sys/src/dll.rs b/modular-sys/src/dll.rs index d0c1b88..a56ea2a 100644 --- a/modular-sys/src/dll.rs +++ b/modular-sys/src/dll.rs @@ -1,4 +1,3 @@ -use crate::core::{BoxModule, Modular, Module}; use crate::{ CBuf, CCallback, CModule, CModuleError, CModuleRef, CSubscribe, CSubscriptionRef, NativeModularVTable, Obj, @@ -6,7 +5,11 @@ use crate::{ use bytes::Bytes; use futures_util::future::BoxFuture; use futures_util::stream::BoxStream; -use futures_util::{FutureExt, Stream, StreamExt}; +use futures_util::{FutureExt, Sink, Stream, StreamExt}; +use modular_core::error::*; +use modular_core::modular::{BoxModule, Modular}; +use modular_core::module::Module; +use modular_core::modules::{ModuleRequest, ModuleResponse}; use once_cell::sync::OnceCell; use parking_lot::Mutex; use std::collections::VecDeque; @@ -48,9 +51,47 @@ impl LibraryModular { Ok(Self { ptr, vtable }) } } - impl Modular for LibraryModular { - fn subscribe(&self, topic: &str) -> anyhow::Result> { + type Stream = BoxStream<'static, (String, Bytes)>; + type Module = BoxModule; + + fn register_module(&self, name: &str, service: S) -> Result<(), RegistryError> + where + S: Service + 'static + Send + Sync, + S::Response: Into + Send + 'static, + S::Error: Into + Send + 'static, + S::Future: Future> + Send + Sync + 'static, + { + let inner = NativeModuleInner { service }; + let module = NativeModule { + inner: Arc::new(Mutex::new(inner)), + handle: Handle::current(), + }; + let module = Box::into_raw(Box::new(module)); + + let module = CModule { + ptr: Obj(module.cast()), + on_invoke: NativeModule::::on_invoke, + on_drop: NativeModule::::on_drop, + }; + + let name = CString::new(name.to_string()).unwrap(); + + let res = unsafe { (self.vtable.register_module)(self.ptr, name.as_ptr(), module, false) }; + match res { + 0 => Ok(()), + _ => Err(RegistryError::AlreadyExists), + } + } + + fn subscribe( + &self, + topic: &str, + _sink: Option, + ) -> Result + where + S: Sink<(String, Bytes), Error = Err> + Send + Sync + 'static, + { let topic = CString::new(topic.to_string()).unwrap(); let sink = NativeSubscriberSink { state: Arc::new(Mutex::new(SubscriberState { @@ -80,42 +121,21 @@ impl Modular for LibraryModular { Ok(stream.boxed()) } - fn publish(&self, topic: &str, data: Bytes) { - let topic = CString::new(topic.to_string()).unwrap(); - let buf = CBuf { - data: data.as_ptr(), - len: data.len(), - }; - - unsafe { (self.vtable.publish)(self.ptr, topic.as_ptr(), buf) } - } - - fn register_module(&self, name: &str, service: S) + fn publish(&self, event: Request) where - S: Service<(String, Bytes), Response = Bytes, Error = LibraryError> + 'static + Send + Sync, - S::Future: Send + Sync + 'static, + Request: Into>, { - let inner = NativeModuleInner { service }; - let module = NativeModule { - inner: Arc::new(Mutex::new(inner)), - handle: Handle::current(), - }; - let module = Box::into_raw(Box::new(module)); - - let module = CModule { - ptr: Obj(module.cast()), - on_invoke: NativeModule::::on_invoke, - on_drop: NativeModule::::on_drop, + let event = event.into(); + let topic = CString::new(event.action.to_string()).unwrap(); + let buf = CBuf { + data: event.body.as_ptr(), + len: event.body.len(), }; - let name = CString::new(name.to_string()).unwrap(); - - unsafe { - (self.vtable.register_module)(self.ptr, name.as_ptr(), module, false); - } + unsafe { (self.vtable.publish)(self.ptr, topic.as_ptr(), buf) } } - fn get_module(&self, name: &str) -> Option { + fn get_module(&self, name: &str) -> Option { let name = CString::new(name.to_string()).unwrap(); let module = unsafe { (self.vtable.get_module_ref)(self.ptr, name.as_ptr()) }; @@ -226,8 +246,10 @@ struct NativeModuleInner { impl NativeModule where - S: Service<(String, Bytes), Response = Bytes, Error = LibraryError> + Send + Sync + 'static, - S::Future: Future> + Send + Sync + 'static, + S: Service + Send + Sync + 'static, + S::Response: Into + Send + 'static, + S::Error: Into, + S::Future: Future> + Send + Sync + 'static, { unsafe extern "system" fn on_invoke( ptr: Obj, @@ -244,19 +266,22 @@ where spawn(async move { let mut service = service.lock(); - let v = service.service.call((method, data)).await; + let v = service + .service + .call(ModuleRequest::new(&method, data)) + .await; match v { Ok(v) => unsafe { let buf = CBuf { - data: v.as_ptr(), - len: v.len(), + data: v.data.as_ptr(), + len: v.data.len(), }; (callback.success)(callback.ptr, buf) }, Err(error) => match error { - LibraryError::UnknownMethod => (callback.unknown_method)(callback.ptr), - LibraryError::CustomError(err) => { + ModuleError::UnknownMethod => (callback.unknown_method)(callback.ptr), + ModuleError::Custom(err) => { let name = err.name.map(|v| CString::new(v).unwrap()); let message = err.message.map(|v| CString::new(v).unwrap()); @@ -269,7 +294,7 @@ where }, ) } - LibraryError::Destroyed => (callback.destroyed)(callback.ptr), + ModuleError::Destroyed => (callback.destroyed)(callback.ptr), }, } }); @@ -282,11 +307,11 @@ where impl Service<(String, Bytes)> for NativeModuleInner where - S: Service<(String, Bytes), Response = Bytes, Error = LibraryError> + 'static, + S: Service<(String, Bytes), Response = Bytes, Error = ModuleError> + 'static, S::Future: Send + Sync + 'static, { type Response = Bytes; - type Error = LibraryError; + type Error = ModuleError; type Future = BoxFuture<'static, Result>; fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll> { @@ -315,10 +340,10 @@ impl Clone for ModuleRef { } impl Module for ModuleRef { - type Future = BoxFuture<'static, Result>; + type Future = BoxFuture<'static, Result>; - fn invoke(&self, method: &str, data: Bytes) -> Self::Future { - let method = CString::new(method).unwrap(); + fn invoke(&self, req: ModuleRequest) -> Self::Future { + let method = CString::new(req.action).unwrap(); let inner = self.0; @@ -334,8 +359,8 @@ impl Module for ModuleRef { }; let buf = CBuf { - data: data.as_ptr(), - len: data.len(), + data: req.body.as_ptr(), + len: req.body.len(), }; unsafe { (inner.vtable.invoke)(inner.ptr, method.as_ptr(), buf, callback) } @@ -346,11 +371,11 @@ impl Module for ModuleRef { struct ModuleCallbackFutureState { waker: Waker, - data: Arc>>>, + data: Arc>>>, } impl ModuleCallbackFutureState { - unsafe extern "system" fn with Result>( + unsafe extern "system" fn with Result>( obj: Obj, f: F, ) { @@ -364,18 +389,20 @@ impl ModuleCallbackFutureState { } unsafe extern "system" fn on_success(this: Obj, data: CBuf) { - let data = Bytes::copy_from_slice(std::slice::from_raw_parts(data.data, data.len)); + let data = ModuleResponse::new(Bytes::copy_from_slice(std::slice::from_raw_parts( + data.data, data.len, + ))); Self::with(this, |state| Ok(data)); } unsafe extern "system" fn unknown_method(this: Obj) { - Self::with(this, |state| Err(LibraryError::UnknownMethod)); + Self::with(this, |state| Err(ModuleError::UnknownMethod)); } unsafe extern "system" fn error(this: Obj, error: CModuleError) { Self::with(this, |state| { - Err(LibraryError::CustomError(CustomLibraryError { + Err(ModuleError::Custom(CustomModuleError { code: error.code, name: if !error.name.is_null() { let temp_name = Some(CStr::from_ptr(error.name).to_string_lossy()); @@ -394,7 +421,7 @@ impl ModuleCallbackFutureState { } unsafe extern "system" fn destroyed(this: Obj) { - Self::with(this, |state| Err(LibraryError::Destroyed)); + Self::with(this, |state| Err(ModuleError::Destroyed)); } } @@ -403,7 +430,7 @@ where F: FnOnce(ModuleCallbackFutureState), { f: Option, - state: Arc>>>, + state: Arc>>>, } impl ModuleCallbackFuture @@ -419,7 +446,7 @@ where } impl Future for ModuleCallbackFuture { - type Output = Result; + type Output = Result; fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { if let Some(v) = self.f.take() { @@ -444,15 +471,3 @@ impl Future for ModuleCallbackFutu } } } - -pub enum LibraryError { - UnknownMethod, - CustomError(CustomLibraryError), - Destroyed, -} - -pub struct CustomLibraryError { - pub code: i32, - pub name: Option, - pub message: Option, -} diff --git a/modular/Cargo.lock b/modular/Cargo.lock deleted file mode 100644 index cc7a729..0000000 --- a/modular/Cargo.lock +++ /dev/null @@ -1,7 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "modular" -version = "0.1.0" diff --git a/modular/Cargo.toml b/modular/Cargo.toml index 64868db..f30eaf3 100644 --- a/modular/Cargo.toml +++ b/modular/Cargo.toml @@ -23,6 +23,8 @@ async-channel = "1" tower = { version = "0.4", features = [ "util" ] } futures-util = "0.3" +modular-core = {version = "0.1", path = "../modular-core"} + [target.'cfg(not(any(target_family = "wasm")))'.dependencies] tokio = { version = "1", features = [ "full" ] } diff --git a/modular/src/core/mod.rs b/modular/src/core/mod.rs index c5020e3..eeea726 100644 --- a/modular/src/core/mod.rs +++ b/modular/src/core/mod.rs @@ -1,25 +1,21 @@ use bytes::Bytes; use futures::Sink; +use modular_core::modules::*; +use std::future::Future; use std::sync::Arc; use tower::Service; -pub mod error; pub mod events; mod module; mod modules_registry; pub mod pattern; -mod req; -mod response; pub mod modules { pub use super::module::*; pub use super::modules_registry::*; - pub use super::req::*; - pub use super::response::*; } use crate::core::pattern::Pattern; -use error::*; use modules::*; #[derive(Default)] @@ -28,55 +24,66 @@ pub struct Modular { events: Arc>, } -impl Modular { - pub fn register_module(&self, name: &str, svc: S) -> Result<(), RegistryError> +impl modular_core::modular::Modular for Modular { + type Stream = (); + type Module = Module; + + fn register_module(&self, name: &str, service: S) -> Result<(), RegistryError> where - S: Service + Send + 'static, - Request: From> + Send + 'static, - S::Response: Into> + Send + 'static, + S: Service + 'static + Send + Sync, + S::Response: Into + Send + 'static, S::Error: Into + Send + 'static, - S::Future: Send + Sync + 'static, + S::Future: Future> + Send + Sync + 'static, { - self.modules.register(name, svc)?; - + self.modules.register(name, service)?; Ok(()) } - pub fn register_or_replace_module(&self, name: &str, svc: S) + fn subscribe( + &self, + topic: &str, + sink: Option, + ) -> Result where - S: Service + Send + 'static, - Request: From> + Send + 'static, - S::Response: Into> + Send + 'static, - S::Error: Into + Send + 'static, - S::Future: Send + Sync + 'static, + S: Sink<(String, Bytes), Error = Err> + Send + Sync + 'static, { - self.modules.register_or_replace(name, svc); + if let Some(sink) = sink { + let pattern = Pattern::parse(topic).map_err(SubscribeError::InvalidPattern)?; + self.events.subscribe(pattern, sink); + } + Ok(()) } - pub fn remove_module(&self, name: &str) { - self.modules.remove(name); + fn publish(&self, event: Request) + where + Request: Into>, + { + let event = event.into(); + if event.action.starts_with("$.sys.") { + return; + } + self.publish_event_inner(event.action(), event.body.clone()); } - pub fn get_module(&self, name: &str) -> Option> { + fn get_module(&self, name: &str) -> Option { self.modules.get(name) } - pub fn subscribe(&self, name: &str, sink: S) -> Result<(), SubscribeError> - where - S: Sink<(String, Bytes), Error = Err> + Send + Sync + 'static, - { - let pattern = Pattern::parse(name).map_err(SubscribeError::InvalidPattern)?; - self.events.subscribe(pattern, sink); - - Ok(()) + fn deregister_module(&self, name: &str) { + self.modules.remove(name); } +} - pub fn publish_event>(&self, path: &str, event: E) { - if path.starts_with("$.sys.") { - return; - } - - self.publish_event_inner(path, event.into()); +impl Modular { + pub fn register_or_replace_module(&self, name: &str, svc: S) + where + S: Service + Send + 'static, + Request: From> + Send + 'static, + S::Response: Into> + Send + 'static, + S::Error: Into + Send + 'static, + S::Future: Send + Sync + 'static, + { + self.modules.register_or_replace(name, svc); } fn publish_event_inner(&self, path: &str, event: Bytes) { diff --git a/modular/src/core/module.rs b/modular/src/core/module.rs index cbda843..07681b1 100644 --- a/modular/src/core/module.rs +++ b/modular/src/core/module.rs @@ -1,7 +1,8 @@ -use crate::core::error::ModuleError; -use crate::core::modules::{BoxModuleService, ModuleRequest, ModuleResponse}; +use crate::core::modules::BoxModuleService; use futures_util::future::BoxFuture; -use futures_util::TryFutureExt; +use futures_util::{FutureExt, TryFutureExt}; +use modular_core::error::ModuleError; +use modular_core::modules::{ModuleRequest, ModuleResponse}; use std::marker::PhantomData; use std::sync::Weak; use std::task::{Context, Poll}; @@ -11,20 +12,29 @@ use tower::Service; #[derive(Clone)] pub struct Module(pub(crate) Weak>>); -impl Module { - pub async fn invoke( - &self, - req: ModuleRequest, - ) -> Result, ModuleError> { +impl modular_core::module::Module + for Module +where + Response: Send + 'static, + Request: Send + 'static, +{ + type Future = BoxFuture< + 'static, + Result, ModuleError>>, ModuleError>, + >; + + fn invoke(&self, req: ModuleRequest) -> Self::Future { let module = match self.0.upgrade() { Some(v) => v, None => { - return Err(ModuleError::Destroyed); + return futures::future::err(ModuleError::Destroyed).boxed(); } }; - - let mut v = module.lock().await; - v.call(req).await + async move { + let mut v = module.lock().await; + Ok(v.call(req)) + } + .boxed() } } diff --git a/modular/src/core/modules_registry.rs b/modular/src/core/modules_registry.rs index c77714c..c025ab5 100644 --- a/modular/src/core/modules_registry.rs +++ b/modular/src/core/modules_registry.rs @@ -1,7 +1,6 @@ -use crate::core::error::ModuleError; use crate::core::module::{Module, ModuleService}; -use crate::core::req::ModuleRequest; -use crate::core::response::ModuleResponse; +use modular_core::error::ModuleError; +use modular_core::modules::*; use parking_lot::RwLock; use std::collections::hash_map::Entry; use std::collections::HashMap; @@ -12,12 +11,6 @@ use tower::Service; pub(crate) type BoxModuleService = tower::util::BoxService, ModuleResponse, ModuleError>; -#[derive(thiserror::Error, Debug)] -pub enum RegistryError { - #[error("module already exists")] - AlreadyExists, -} - pub struct ModulesRegistry { modules: RwLock>>>>, }