diff --git a/Cargo.lock b/Cargo.lock index d8f2725..c6c665c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,21 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +version = 4 [[package]] name = "aho-corasick" @@ -127,17 +112,6 @@ version = "4.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4eb2cdb97421e01129ccb49169d8279ed21e829929144f4a22a6e54ac549ca1" -[[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.38", -] - [[package]] name = "atomic-waker" version = "1.1.2" @@ -150,21 +124,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" -[[package]] -name = "backtrace" -version = "0.3.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - [[package]] name = "bincode" version = "1.3.3" @@ -263,7 +222,7 @@ dependencies = [ "num-traits", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.117", ] [[package]] @@ -273,7 +232,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3e13f66a2f95e32a39eaa81f6b95d42878ca0e1db0c7543723dfe12557e860" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -368,7 +327,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.117", ] [[package]] @@ -414,12 +373,6 @@ dependencies = [ "windows", ] -[[package]] -name = "gimli" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" - [[package]] name = "gloo-timers" version = "0.2.6" @@ -455,7 +408,7 @@ checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" dependencies = [ "hermit-abi", "libc", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -490,9 +443,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.148" +version = "0.2.186" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b" +checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66" [[package]] name = "linux-raw-sys" @@ -548,24 +501,15 @@ version = "2.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" -[[package]] -name = "miniz_oxide" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" -dependencies = [ - "adler", -] - [[package]] name = "mio" -version = "0.8.8" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" +checksum = "50b7e5b27aa02a74bac8c3f23f448f8d87ff11f92d3aac1a6ed369ee08cc56c1" dependencies = [ "libc", "wasi", - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -608,25 +552,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.32.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" -dependencies = [ - "memchr", -] - [[package]] name = "once_cell" version = "1.18.0" @@ -694,7 +619,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.117", ] [[package]] @@ -733,23 +658,23 @@ dependencies = [ "libc", "log", "pin-project-lite", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] name = "proc-macro2" -version = "1.0.67" +version = "1.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.33" +version = "1.0.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" dependencies = [ "proc-macro2", ] @@ -811,35 +736,35 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" name = "rspc" version = "0.1.0" dependencies = [ - "async-std", - "async-trait", "futures", "oneshot", - "pin-project", + "rspc_dev_utilities", "rspc_macros", "serde", - "serde_json", - "syn 2.0.38", "thiserror", "tokio", "tokio-serde", "tokio-util", ] +[[package]] +name = "rspc_dev_utilities" +version = "0.1.0" +dependencies = [ + "async-std", + "rspc", + "serde", + "tokio", +] + [[package]] name = "rspc_macros" version = "0.1.0" dependencies = [ "quote", - "syn 2.0.38", + "syn 2.0.117", ] -[[package]] -name = "rustc-demangle" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" - [[package]] name = "rustix" version = "0.37.25" @@ -851,7 +776,7 @@ dependencies = [ "io-lifetimes", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -880,22 +805,32 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "serde" -version = "1.0.189" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.189" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.117", ] [[package]] @@ -954,12 +889,12 @@ dependencies = [ [[package]] name = "socket2" -version = "0.5.4" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4031e820eb552adee9295814c0ced9e5cf38ddf1e8b7d566d6de8e2538ea989e" +checksum = "3a766e1110788c36f4fa1c2b71b387a7815aa65f88ce0229841826633d93723e" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -975,9 +910,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.38" +version = "2.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" dependencies = [ "proc-macro2", "quote", @@ -1001,7 +936,7 @@ checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.117", ] [[package]] @@ -1016,32 +951,30 @@ dependencies = [ [[package]] name = "tokio" -version = "1.32.0" +version = "1.52.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17ed6077ed6cd6c74735e21f37eb16dc3935f96878b1fe961074089cc80893f9" +checksum = "b67dee974fe86fd92cc45b7a95fdd2f99a36a6d7b0d431a231178d3d670bbcc6" dependencies = [ - "backtrace", "bytes", "libc", "mio", - "num_cpus", "parking_lot", "pin-project-lite", "signal-hook-registry", - "socket2 0.5.4", + "socket2 0.6.3", "tokio-macros", - "windows-sys", + "windows-sys 0.61.2", ] [[package]] name = "tokio-macros" -version = "2.1.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" +checksum = "385a6cb71ab9ab790c5fe8d67f1645e6c450a7ce006a33de03daa956cf70a496" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.117", ] [[package]] @@ -1093,7 +1026,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.117", ] [[package]] @@ -1186,7 +1119,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.117", "wasm-bindgen-shared", ] @@ -1220,7 +1153,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.117", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1272,6 +1205,12 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + [[package]] name = "windows-sys" version = "0.48.0" @@ -1281,6 +1220,15 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + [[package]] name = "windows-targets" version = "0.48.5" diff --git a/Cargo.toml b/Cargo.toml index 93e17a0..8f40df0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,22 +1,44 @@ +[workspace] +resolver = "3" +members = ["utilities"] + +[dev-dependencies] +rspc_dev_utilities = { path = "utilities" } + +[features] +default = ["full"] +full = ["serde","channel"] +channel = ["dep:oneshot"] +serde = ["dep:serde", "rspc_macros/serde"] + [package] name = "rspc" version = "0.1.0" edition = "2021" +include = ["/src"] [dependencies] -serde = { version = "1.0", features = ["derive"] } -futures = "0.3" -tokio = { version = "1.0", features = ["full"] } -syn = { version = "2.0", features = ["full"] } rspc_macros = { path = "macros", version = "0.1" } +# necessary dependencies +futures = "0.3" thiserror = "1.0.49" -async-trait = "0.1.73" -async-std = "1.12.0" +tokio = { version = "1.0", features = ["full"] } tokio-serde = { version = "0.8.0", features=["json","bincode"] } -pin-project = "1.1.3" tokio-util = { version = "0.7.10", features=["codec"] } -serde_json = "1.0.108" -oneshot = { version = "0.1.6", features=["std"] } +oneshot = { version = "0.1.6", features=["std"], optional = true } +serde = { version = "1.0", features = ["derive"], optional = true } [lib] + +[[example]] +name = "channel_sync" +required-features = ["channel"] + +[[example]] +name = "channel_async" +required-features = ["channel"] + +[[example]] +name = "tcp" +required-features = ["serde"] diff --git a/README.md b/README.md index 267a773..0425b14 100644 --- a/README.md +++ b/README.md @@ -3,12 +3,14 @@ Proof of concept RPC framework focused on ease of use. It works by calling the macro `#[rspc::service]` on an impl block, and code is generated for the resulting Server and Client objects. +You can then instantiate a Server/Client on the desired transporter. The Server objects own the original struct data and implements listen functions.
The Client objects must be provided a connection, and replicates all the functions of the impl block where the macro was called. -The Server implements read-write locking, there can be many reads at once, but only one write. -Requests are not errored upon write-lock, but instead waited for. +The Server implements read-write locking, there can be many reads at once, but only one write. Requests are not errored upon write-lock, but instead waited for. + +> If you wish to implement parallel writes, you must implement it with internal parallelism as you would in normal rust, for instance with immutable functions and internal read-write locks The Client object cannot be cloned. Instead all function calls are immutable, so a reference can be shared to all. @@ -17,7 +19,6 @@ Currently only implements local thread messaging. Serialized TCP transport is un Example: ```rs use rspc::transport::{channel, ClientTransporter,ServerTransporter}; -use rspc::service; use serde::{Deserialize, Serialize}; @@ -26,7 +27,8 @@ pub struct MyStruct { my_vec: Vec, } -#[service] +// Functions to instanciate as RPC +#[rspc::service] impl MyStruct { pub fn len(&self) -> usize { @@ -44,9 +46,11 @@ impl MyStruct #[tokio::test] async fn test() { + // Create the server data structure let my_data = MyStruct { my_vec: Vec::new(), }; + // Instanciate a client and server let (c,s) = channel::new_async(); let srv_thread = tokio::spawn(async move { @@ -65,3 +69,10 @@ async fn test() { ``` See [example](example) for an more detailed example usage + +### Internal logic and determinism + +RSPC is built on rust logic and works with type determinism rather than serializing. +Serializing is used for transports that require it (such as TCP with serde), but is otherwise unused in code logic. + +Determinism is achieved through enum autogeneration by the macro `rscp::service`, which is used for internal transport logic diff --git a/example/Cargo.lock b/example/Cargo.lock deleted file mode 100644 index 22b7ee3..0000000 --- a/example/Cargo.lock +++ /dev/null @@ -1,1333 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "anyhow" -version = "1.0.86" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" - -[[package]] -name = "async-channel" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81953c529336010edd6d8e358f886d9581267795c61b19475b71314bffa46d35" -dependencies = [ - "concurrent-queue", - "event-listener 2.5.3", - "futures-core", -] - -[[package]] -name = "async-channel" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89b47800b0be77592da0afd425cc03468052844aff33b84e33cc696f64e77b6a" -dependencies = [ - "concurrent-queue", - "event-listener-strategy", - "futures-core", - "pin-project-lite", -] - -[[package]] -name = "async-executor" -version = "1.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8828ec6e544c02b0d6691d21ed9f9218d0384a82542855073c2a3f58304aaf0" -dependencies = [ - "async-task", - "concurrent-queue", - "fastrand 2.1.0", - "futures-lite 2.3.0", - "slab", -] - -[[package]] -name = "async-global-executor" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05b1b633a2115cd122d73b955eadd9916c18c8f510ec9cd1686404c60ad1c29c" -dependencies = [ - "async-channel 2.3.1", - "async-executor", - "async-io 2.3.3", - "async-lock 3.4.0", - "blocking", - "futures-lite 2.3.0", - "once_cell", -] - -[[package]] -name = "async-io" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fc5b45d93ef0529756f812ca52e44c221b35341892d3dcc34132ac02f3dd2af" -dependencies = [ - "async-lock 2.8.0", - "autocfg", - "cfg-if", - "concurrent-queue", - "futures-lite 1.13.0", - "log", - "parking", - "polling 2.8.0", - "rustix 0.37.27", - "slab", - "socket2 0.4.10", - "waker-fn", -] - -[[package]] -name = "async-io" -version = "2.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d6baa8f0178795da0e71bc42c9e5d13261aac7ee549853162e66a241ba17964" -dependencies = [ - "async-lock 3.4.0", - "cfg-if", - "concurrent-queue", - "futures-io", - "futures-lite 2.3.0", - "parking", - "polling 3.7.2", - "rustix 0.38.34", - "slab", - "tracing", - "windows-sys 0.52.0", -] - -[[package]] -name = "async-lock" -version = "2.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "287272293e9d8c41773cec55e365490fe034813a2f172f502d6ddcf75b2f582b" -dependencies = [ - "event-listener 2.5.3", -] - -[[package]] -name = "async-lock" -version = "3.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff6e472cdea888a4bd64f342f09b3f50e1886d32afe8df3d663c01140b811b18" -dependencies = [ - "event-listener 5.3.1", - "event-listener-strategy", - "pin-project-lite", -] - -[[package]] -name = "async-std" -version = "1.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62565bb4402e926b29953c785397c6dc0391b7b446e45008b0049eb43cec6f5d" -dependencies = [ - "async-channel 1.9.0", - "async-global-executor", - "async-io 1.13.0", - "async-lock 2.8.0", - "crossbeam-utils", - "futures-channel", - "futures-core", - "futures-io", - "futures-lite 1.13.0", - "gloo-timers", - "kv-log-macro", - "log", - "memchr", - "once_cell", - "pin-project-lite", - "pin-utils", - "slab", - "wasm-bindgen-futures", -] - -[[package]] -name = "async-task" -version = "4.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de" - -[[package]] -name = "async-trait" -version = "0.1.80" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.67", -] - -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "backtrace" -version = "0.3.73" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "bincode" -version = "1.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" -dependencies = [ - "serde", -] - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "blocking" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "703f41c54fc768e63e091340b424302bb1c29ef4aa0c7f10fe849dfb114d29ea" -dependencies = [ - "async-channel 2.3.1", - "async-task", - "futures-io", - "futures-lite 2.3.0", - "piper", -] - -[[package]] -name = "bumpalo" -version = "3.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - -[[package]] -name = "cc" -version = "1.0.99" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" - -[[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.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" -dependencies = [ - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" - -[[package]] -name = "educe" -version = "0.4.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f0042ff8246a363dbe77d2ceedb073339e85a804b9a47636c6e016a9a32c05f" -dependencies = [ - "enum-ordinalize", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "enum-ordinalize" -version = "3.1.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bf1fa3f06bbff1ea5b1a9c7b14aa992a39657db60a2759457328d7e058f49ee" -dependencies = [ - "num-bigint", - "num-traits", - "proc-macro2", - "quote", - "syn 2.0.67", -] - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "event-listener" -version = "2.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" - -[[package]] -name = "event-listener" -version = "5.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6032be9bd27023a771701cc49f9f053c751055f71efb2e0ae5c15809093675ba" -dependencies = [ - "concurrent-queue", - "parking", - "pin-project-lite", -] - -[[package]] -name = "event-listener-strategy" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f214dc438f977e6d4e3500aaa277f5ad94ca83fbbd9b1a15713ce2344ccc5a1" -dependencies = [ - "event-listener 5.3.1", - "pin-project-lite", -] - -[[package]] -name = "fastrand" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" -dependencies = [ - "instant", -] - -[[package]] -name = "fastrand" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-lite" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce" -dependencies = [ - "fastrand 1.9.0", - "futures-core", - "futures-io", - "memchr", - "parking", - "pin-project-lite", - "waker-fn", -] - -[[package]] -name = "futures-lite" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52527eb5074e35e9339c6b4e8d12600c7128b68fb25dcb9fa9dec18f7c25f3a5" -dependencies = [ - "fastrand 2.1.0", - "futures-core", - "futures-io", - "parking", - "pin-project-lite", -] - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.67", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "gimli" -version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" - -[[package]] -name = "gloo-timers" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b995a66bb87bebce9a0f4a95aed01daca4872c050bfcb21653361c03bc35e5c" -dependencies = [ - "futures-channel", - "futures-core", - "js-sys", - "wasm-bindgen", -] - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "hermit-abi" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc" - -[[package]] -name = "instant" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "io-lifetimes" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" -dependencies = [ - "hermit-abi 0.3.9", - "libc", - "windows-sys 0.48.0", -] - -[[package]] -name = "itoa" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" - -[[package]] -name = "js-sys" -version = "0.3.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" -dependencies = [ - "wasm-bindgen", -] - -[[package]] -name = "kv-log-macro" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" -dependencies = [ - "log", -] - -[[package]] -name = "libc" -version = "0.2.155" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" - -[[package]] -name = "linux-raw-sys" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" - -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "log" -version = "0.4.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" -dependencies = [ - "value-bag", -] - -[[package]] -name = "memchr" -version = "2.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" - -[[package]] -name = "miniz_oxide" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" -dependencies = [ - "adler", -] - -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - -[[package]] -name = "num-bigint" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c165a9ab64cf766f73521c0dd2cfdff64f488b8f0b3e621face3462d3db536d7" -dependencies = [ - "num-integer", - "num-traits", -] - -[[package]] -name = "num-integer" -version = "0.1.46" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" -dependencies = [ - "num-traits", -] - -[[package]] -name = "num-traits" -version = "0.2.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" -dependencies = [ - "autocfg", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi 0.3.9", - "libc", -] - -[[package]] -name = "object" -version = "0.36.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" -dependencies = [ - "memchr", -] - -[[package]] -name = "once_cell" -version = "1.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" - -[[package]] -name = "oneshot" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e296cf87e61c9cfc1a61c3c63a0f7f286ed4554e0e22be84e8a38e1d264a2a29" - -[[package]] -name = "parking" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" - -[[package]] -name = "parking_lot" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - -[[package]] -name = "pin-project" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.67", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "piper" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae1d5c74c9876f070d3e8fd503d748c7d974c3e48da8f41350fa5222ef9b4391" -dependencies = [ - "atomic-waker", - "fastrand 2.1.0", - "futures-io", -] - -[[package]] -name = "polling" -version = "2.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b2d323e8ca7996b3e23126511a523f7e62924d93ecd5ae73b333815b0eb3dce" -dependencies = [ - "autocfg", - "bitflags 1.3.2", - "cfg-if", - "concurrent-queue", - "libc", - "log", - "pin-project-lite", - "windows-sys 0.48.0", -] - -[[package]] -name = "polling" -version = "3.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3ed00ed3fbf728b5816498ecd316d1716eecaced9c0c8d2c5a6740ca214985b" -dependencies = [ - "cfg-if", - "concurrent-queue", - "hermit-abi 0.4.0", - "pin-project-lite", - "rustix 0.38.34", - "tracing", - "windows-sys 0.52.0", -] - -[[package]] -name = "proc-macro2" -version = "1.0.86" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "redox_syscall" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c82cf8cff14456045f55ec4241383baeff27af886adb72ffb2162f99911de0fd" -dependencies = [ - "bitflags 2.5.0", -] - -[[package]] -name = "rspc" -version = "0.1.0" -dependencies = [ - "async-std", - "async-trait", - "futures", - "oneshot", - "pin-project", - "rspc_macros", - "serde", - "serde_json", - "syn 2.0.67", - "thiserror", - "tokio", - "tokio-serde", - "tokio-util", -] - -[[package]] -name = "rspc_example" -version = "0.1.0" -dependencies = [ - "anyhow", - "async-std", - "rspc", - "serde", - "tokio", -] - -[[package]] -name = "rspc_macros" -version = "0.1.0" -dependencies = [ - "quote", - "syn 2.0.67", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "rustix" -version = "0.37.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fea8ca367a3a01fe35e6943c400addf443c0f57670e6ec51196f71a4b8762dd2" -dependencies = [ - "bitflags 1.3.2", - "errno", - "io-lifetimes", - "libc", - "linux-raw-sys 0.3.8", - "windows-sys 0.48.0", -] - -[[package]] -name = "rustix" -version = "0.38.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags 2.5.0", - "errno", - "libc", - "linux-raw-sys 0.4.14", - "windows-sys 0.52.0", -] - -[[package]] -name = "ryu" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "serde" -version = "1.0.203" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.203" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.67", -] - -[[package]] -name = "serde_json" -version = "1.0.117" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.4.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" -dependencies = [ - "libc", - "winapi", -] - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[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.67" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff8655ed1d86f3af4ee3fd3263786bc14245ad17c4c7e85ba7187fb3ae028c90" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "thiserror" -version = "1.0.61" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.61" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.67", -] - -[[package]] -name = "tokio" -version = "1.38.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" -dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "num_cpus", - "parking_lot", - "pin-project-lite", - "signal-hook-registry", - "socket2 0.5.7", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.67", -] - -[[package]] -name = "tokio-serde" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "911a61637386b789af998ee23f50aa30d5fd7edcec8d6d3dedae5e5815205466" -dependencies = [ - "bincode", - "bytes", - "educe", - "futures-core", - "futures-sink", - "pin-project", - "serde", - "serde_json", -] - -[[package]] -name = "tokio-util" -version = "0.7.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - -[[package]] -name = "tracing" -version = "0.1.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" -dependencies = [ - "pin-project-lite", - "tracing-core", -] - -[[package]] -name = "tracing-core" -version = "0.1.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "value-bag" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a84c137d37ab0142f0f2ddfe332651fdbf252e7b7dbb4e67b6c1f1b2e925101" - -[[package]] -name = "waker-fn" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "317211a0dc0ceedd78fb2ca9a44aed3d7b9b26f81870d485c07122b4350673b7" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wasm-bindgen" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" -dependencies = [ - "cfg-if", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" -dependencies = [ - "bumpalo", - "log", - "once_cell", - "proc-macro2", - "quote", - "syn 2.0.67", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-futures" -version = "0.4.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76bc14366121efc8dbb487ab05bcc9d346b3b5ec0eaa76e46594cabbe51762c0" -dependencies = [ - "cfg-if", - "js-sys", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.67", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" - -[[package]] -name = "web-sys" -version = "0.3.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - -[[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.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/example/src/main.rs b/examples/channel_async.rs similarity index 88% rename from example/src/main.rs rename to examples/channel_async.rs index 9630487..fd0b930 100644 --- a/example/src/main.rs +++ b/examples/channel_async.rs @@ -1,21 +1,12 @@ -pub mod data; - -use data::{ +use rspc_dev_utilities::test_data::{ dur_to_str, make_test_data, TestData, TestDataClient, TestDataServer, TestEnum, DATASIZE, }; use tokio::join; -use rspc::transport::serde::TcpClient; - use rspc::transport; #[tokio::main] -async fn main() -> anyhow::Result<()> { - // let t = TcpClient::connect("127.0.0.1:3306").await.unwrap(); - // let client = t.spawn().await; - - // let client = TestDataClient::new(client); - +async fn main() -> Result<(), Box> { let (c, s) = transport::channel::new_async(); let data: TestData = make_test_data(DATASIZE); diff --git a/examples/channel_sync.rs b/examples/channel_sync.rs new file mode 100644 index 0000000..3a057e4 --- /dev/null +++ b/examples/channel_sync.rs @@ -0,0 +1,63 @@ +use rspc_dev_utilities::test_data::{ + dur_to_str, make_test_data, TestData, TestDataClient, TestDataServer, TestEnum, DATASIZE, +}; +use tokio::join; + +use rspc::transport; + +#[tokio::main] +async fn main() -> Result<(), Box> { + let (c, s) = transport::channel::new_sync(); + let data: TestData = make_test_data(DATASIZE); + + let srv_thread = tokio::spawn(async move { + let mut server = TestDataServer::from(data); + server.listen(s).await + }); + + let client = TestDataClient::new(c); + let clientref = &client; + + let job1 = async { + let now = std::time::Instant::now(); + assert_eq!(DATASIZE, client.len().await.unwrap()); + println!("len: {}", dur_to_str(now.elapsed())); + + let now = std::time::Instant::now(); + assert_eq!(267914296, clientref.fib(42).await.unwrap()); + println!("fib1: {}", dur_to_str(now.elapsed())); + }; + + let job2 = async { + let now = std::time::Instant::now(); + assert_eq!(DATASIZE, client.len().await.unwrap()); + println!("len: {}", dur_to_str(now.elapsed())); + + let now = std::time::Instant::now(); + assert_eq!(4, client.calc().await.unwrap().unwrap_or(0)); + println!("calc: {}", dur_to_str(now.elapsed())); + + let cdat = make_test_data(DATASIZE); + let now = std::time::Instant::now(); + assert_eq!(8, client.calc_add(cdat).await.unwrap().unwrap_or(0)); + println!("calc_add: {}", dur_to_str(now.elapsed())); + + let now = std::time::Instant::now(); + assert_eq!(267914296, client.fib(42).await.unwrap()); + println!("fib2: {}", dur_to_str(now.elapsed())); + + let now = std::time::Instant::now(); + clientref.push((false, TestEnum::NoValue)).await.unwrap(); + println!("push: {}", dur_to_str(now.elapsed())); + + let now = std::time::Instant::now(); + assert_eq!(DATASIZE + 1, client.len().await.unwrap()); + println!("len: {}", dur_to_str(now.elapsed())); + }; + + join!(job1, job2); + client.stop().await.unwrap(); + srv_thread.await.unwrap().unwrap(); + + Ok(()) +} diff --git a/examples/tcp.rs b/examples/tcp.rs new file mode 100644 index 0000000..d1d0c69 --- /dev/null +++ b/examples/tcp.rs @@ -0,0 +1,62 @@ +use rspc_dev_utilities::test_data::{ + dur_to_str, make_test_data, TestData, TestDataClient, TestDataServer, TestEnum, DATASIZE, +}; +use tokio::join; + +use rspc::transport::serde::TcpClient; + +use rspc::transport; + +#[tokio::main] +async fn main() -> Result<(), Box> { + let t = TcpClient::connect("127.0.0.1:6543").await.unwrap(); + let client = t.spawn().await; + + // todo : server + + let client = TestDataClient::new(client); + + let clientref = &client; + + let job1 = async { + let now = std::time::Instant::now(); + assert_eq!(DATASIZE, client.len().await.unwrap()); + println!("len: {}", dur_to_str(now.elapsed())); + + let now = std::time::Instant::now(); + assert_eq!(267914296, clientref.fib(42).await.unwrap()); + println!("fib1: {}", dur_to_str(now.elapsed())); + }; + + let job2 = async { + let now = std::time::Instant::now(); + assert_eq!(DATASIZE, client.len().await.unwrap()); + println!("len: {}", dur_to_str(now.elapsed())); + + let now = std::time::Instant::now(); + assert_eq!(4, client.calc().await.unwrap().unwrap_or(0)); + println!("calc: {}", dur_to_str(now.elapsed())); + + let cdat = make_test_data(DATASIZE); + let now = std::time::Instant::now(); + assert_eq!(8, client.calc_add(cdat).await.unwrap().unwrap_or(0)); + println!("calc_add: {}", dur_to_str(now.elapsed())); + + let now = std::time::Instant::now(); + assert_eq!(267914296, client.fib(42).await.unwrap()); + println!("fib2: {}", dur_to_str(now.elapsed())); + + let now = std::time::Instant::now(); + clientref.push((false, TestEnum::NoValue)).await.unwrap(); + println!("push: {}", dur_to_str(now.elapsed())); + + let now = std::time::Instant::now(); + assert_eq!(DATASIZE + 1, client.len().await.unwrap()); + println!("len: {}", dur_to_str(now.elapsed())); + }; + + join!(job1, job2); + client.stop().await.unwrap(); + + Ok(()) +} diff --git a/macros/Cargo.lock b/macros/Cargo.lock new file mode 100644 index 0000000..d230b9b --- /dev/null +++ b/macros/Cargo.lock @@ -0,0 +1,46 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rspc_macros" +version = "0.1.0" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "syn" +version = "2.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" diff --git a/macros/Cargo.toml b/macros/Cargo.toml index 511be8f..d0f1f8c 100644 --- a/macros/Cargo.toml +++ b/macros/Cargo.toml @@ -5,6 +5,10 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[features] +full = ["serde"] +serde = [] + [dependencies] #anyhow = "1.0" #futures = "0.3" diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 33ebb28..f4b6690 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -48,7 +48,7 @@ fn snake_to_upper_camel(ident_str: &str) -> String { } struct RpcMethod { - pub attrs: Vec, + pub _attrs: Vec, pub sig: Signature, pub reciever: Option, pub args: Vec, @@ -57,8 +57,8 @@ struct RpcMethod { struct Service { pub ident: Ident, pub rpcs: Vec, - pub item: ItemImpl, - pub types: Vec, + pub _item: ItemImpl, + pub _types: Vec, } impl TryFrom for RpcMethod { @@ -93,7 +93,7 @@ impl TryFrom for RpcMethod { } Ok(RpcMethod { - attrs: value.attrs, + _attrs: value.attrs, sig: value.sig, reciever, args, @@ -178,8 +178,8 @@ impl Parse for Service { Ok(Self { ident, rpcs, - item, - types: typeitems, + _item: item, + _types: typeitems, }) } } @@ -191,8 +191,8 @@ pub fn service(_attr: TokenStream, mut input: TokenStream) -> TokenStream { let Service { ident, rpcs, - item: _, - types: _, + _item: _, + _types: _, } = parse_macro_input!(inputclone as Service); let transport_request = &format_ident!("{}TransportRequest", ident); @@ -269,15 +269,21 @@ pub fn service(_attr: TokenStream, mut input: TokenStream) -> TokenStream { }) .collect(); + let serde_derives = if cfg!(feature = "serde") { + quote! { serde::Serialize, serde::Deserialize } + } else { + quote! {} + }; + let t = quote! { - #[derive(PartialEq,Debug,Serialize,Deserialize)] + #[derive(PartialEq, Debug, #serde_derives)] pub enum #transport_request { #( #fn_names_camel(#arg_types) ),* , Stop, } - #[derive(PartialEq,Debug,Serialize,Deserialize)] + #[derive(PartialEq, Debug, #serde_derives)] pub enum #transport_response { #( #fn_names_camel(#outs) ),* , Stop, @@ -296,13 +302,13 @@ pub fn service(_attr: TokenStream, mut input: TokenStream) -> TokenStream { } pub struct #server { - obj: std::sync::Arc>, + obj: std::sync::Arc>, } impl From<#ident> for #server { fn from(obj: #ident) -> Self { Self { - obj: std::sync::Arc::new(async_std::sync::RwLock::new(obj)), + obj: std::sync::Arc::new(tokio::sync::RwLock::new(obj)), } } } diff --git a/src/lib.rs b/src/lib.rs index 86c3011..56150b6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,55 +1,2 @@ - pub mod transport; pub use rspc_macros::service; - - -#[cfg(test)] -mod tests { - use super::transport::{channel, ClientTransporter,ServerTransporter}; - use super::service; - - use serde::{Deserialize, Serialize}; - // use rspc::transport::{ClientTransporter,ServerTransporter}; - - #[derive(Serialize,Deserialize)] - pub struct MyStruct { - my_vec: Vec, - } - - #[service] - impl MyStruct - { - pub fn len(&self) -> usize { - self.my_vec.len() - } - - pub fn push(&mut self, val: String) { - self.my_vec.push(val) - } - - pub fn pop(&mut self) -> Option { - self.my_vec.pop() - } - } - - #[tokio::test] - async fn test() { - let my_data = MyStruct { - my_vec: Vec::new(), - }; - let (c,s) = channel::new_async(); - - let srv_thread = tokio::spawn(async move { - let mut server = MyStructServer::from(my_data); - server.listen(s).await - } ); - - let client = MyStructClient::new(c); - assert_eq!(client.len().await.unwrap(), 0); - client.push("Hello world!".to_string()).await.unwrap(); - assert_eq!(client.len().await.unwrap(), 1); - assert_eq!(client.pop().await.unwrap(), Some("Hello world!".to_string())); - client.stop().await.unwrap(); - srv_thread.await.unwrap().unwrap(); - } -} diff --git a/src/transport/channel.rs b/src/transport/channel.rs index 7e67090..7cdd6a0 100644 --- a/src/transport/channel.rs +++ b/src/transport/channel.rs @@ -7,8 +7,6 @@ use thiserror::Error; use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender}; use tokio::sync::oneshot; -use async_trait::async_trait; - use super::{ClientTransporter, ServerTransporter}; #[derive(Error, Debug)] @@ -29,25 +27,24 @@ pub struct ChannelClient { channel: UnboundedSender<(T, oneshot::Sender)>, } -/// Server endpoint of a synchronous channel +/// Server endpoint of a synchronous channel. +/// +/// Synchronous channels can only process one job at a time. If you want job concurrency refer to [new_async](new_async) and [AsyncChannelServer](AsyncChannelServer) +/// +/// Unpon recieving a stop signal, jobs currently pending recv() will not be processed. +/// Said jobs will continue waiting until either the server listens again, or the server is dropped. pub struct SyncChannelServer { channel: UnboundedReceiver<(T, oneshot::Sender)>, } -/// Create a new synchronous channel client/server instance. +/// Create a new synchronous channel client/server instance. See [SyncChannelServer](SyncChannelServer) /// -/// Synchronous channels can only process one job at a time. -/// If you want job concurrency refer to new_async() and Asynchronous channels -/// -/// Unpon recieving a stop signal, jobs currently pending recv() will not be processed. -/// Said jobs will continue waiting until either the server listens again, or the server is dropped. +/// Synchronous channels can only process one job at a time. If you want job concurrency refer to [new_async](new_async) and [AsyncChannelServer](AsyncChannelServer) /// /// Example: /// ```no_run -/// use serde::{Serialize,Deserialize}; /// use rspc::transport::{channel, ClientTransporter,ServerTransporter}; /// -/// #[derive(Serialize,Deserialize)] /// pub struct MyStruct; /// /// #[rspc::service] @@ -72,12 +69,14 @@ pub fn new_sync() -> (ChannelClient, SyncChannelServer) { ) } -impl ChannelClient +impl ClientTransporter for ChannelClient where T: Send + Sync, R: Send + Sync, { - pub async fn internal_request(&self, data: T) -> Result { + type Error = Error; + + async fn request(&self, data: T) -> Result { let (t, r) = oneshot::channel(); self.channel .send((data, t)) @@ -87,20 +86,6 @@ where } } -#[async_trait] -impl ClientTransporter for ChannelClient -where - T: Send + Sync, - R: Send + Sync, -{ - type Error = Error; - - async fn request(&self, data: T) -> Result { - self.internal_request(data).await - } -} - -#[async_trait] impl ServerTransporter for SyncChannelServer where T: Send + Sync, @@ -134,23 +119,21 @@ where } } -pub struct AsyncChannelServer { - channel: UnboundedReceiver<(T, oneshot::Sender)>, -} - -/// Create a new asynchronous channel client/server instance. -/// +/// Server endpoint of an asynchronous channel. /// Can process any number of jobs in parallel. /// /// Unpon recieving a stop signal, pending jobs are finished and reponded to, but new jobs are not processed. /// Said new jobs will continue waiting until either the server listens again, or the server is dropped. +pub struct AsyncChannelServer { + channel: UnboundedReceiver<(T, oneshot::Sender)>, +} + +/// Create a new asynchronous channel client/server instance. See AsyncChannelServer /// /// Example: /// ```no_run -/// use serde::{Serialize,Deserialize}; /// use rspc::transport::{channel, ClientTransporter,ServerTransporter}; /// -/// #[derive(Serialize,Deserialize)] /// pub struct MyStruct; /// /// #[rspc::service] @@ -234,7 +217,6 @@ where } } -#[async_trait] impl ServerTransporter for AsyncChannelServer where T: Send + Sync, diff --git a/src/transport/mod.rs b/src/transport/mod.rs index e851ab0..ad43acf 100644 --- a/src/transport/mod.rs +++ b/src/transport/mod.rs @@ -1,7 +1,8 @@ -use async_trait::async_trait; use futures::{future::BoxFuture, stream::FuturesUnordered, Future, StreamExt}; +#[cfg(feature = "channel")] pub mod channel; +#[cfg(feature = "serde")] pub mod serde; /// Definition of a client transporter for RSPC. @@ -10,10 +11,9 @@ pub mod serde; /// - ClientTransporter is a producer object, can be single-producer or multi-producer. /// - ClientTransporter must be immutable. If a client implementation requires self mutability, /// use Mutex, RwLock, or similar tools to mutate values without requiring self mutability -#[async_trait] pub trait ClientTransporter { type Error: std::fmt::Debug; - async fn request(&self, data: T) -> Result; + fn request(&self, data: T) -> impl std::future::Future> + Send; } /// Definition of a server transporter for RSPC. @@ -22,15 +22,14 @@ pub trait ClientTransporter { /// - ServerTransporter is a single-consumer object /// - Upon recieving a stop request (handler function return None), server must respond with stop_response if specified to only this request and none other. /// Finishing and responding to pending jobs is optional. -#[async_trait] pub trait ServerTransporter { type Error: std::fmt::Debug; - async fn listen( + fn listen( &mut self, handler: F, stop_response: Option, userdata: D, - ) -> Result<(), Self::Error> + ) -> impl std::future::Future> + Send where FR: Future> + Send + 'static, F: Fn(T, &D) -> FR + Send + Sync + Copy + 'static, diff --git a/src/transport/serde.rs b/src/transport/serde.rs index 89ffc64..1ac9f3a 100644 --- a/src/transport/serde.rs +++ b/src/transport/serde.rs @@ -1,4 +1,3 @@ -use async_trait::async_trait; use futures::future::BoxFuture; use futures::prelude::*; use serde::{Deserialize, Serialize}; @@ -162,7 +161,6 @@ where } } -#[async_trait] impl ServerTransporter for TcpServer where T: for<'a> Deserialize<'a> + Serialize + Send + Sync + Unpin, diff --git a/tests/channel_async.rs b/tests/channel_async.rs new file mode 100644 index 0000000..3a41c53 --- /dev/null +++ b/tests/channel_async.rs @@ -0,0 +1,46 @@ +#[cfg(test)] +#[cfg(feature = "channel")] +mod tests { + use rspc::transport::{channel, ClientTransporter, ServerTransporter}; + + pub struct MyStruct { + my_vec: Vec, + } + + #[rspc::service] + impl MyStruct { + pub fn len(&self) -> usize { + self.my_vec.len() + } + + pub fn push(&mut self, val: String) { + self.my_vec.push(val) + } + + pub fn pop(&mut self) -> Option { + self.my_vec.pop() + } + } + + #[tokio::test] + async fn test() { + let my_data = MyStruct { my_vec: Vec::new() }; + let (c, s) = channel::new_async(); + + let srv_thread = tokio::spawn(async move { + let mut server = MyStructServer::from(my_data); + server.listen(s).await + }); + + let client = MyStructClient::new(c); + assert_eq!(client.len().await.unwrap(), 0); + client.push("Hello world!".to_string()).await.unwrap(); + assert_eq!(client.len().await.unwrap(), 1); + assert_eq!( + client.pop().await.unwrap(), + Some("Hello world!".to_string()) + ); + client.stop().await.unwrap(); + srv_thread.await.unwrap().unwrap(); + } +} diff --git a/tests/channel_sync.rs b/tests/channel_sync.rs new file mode 100644 index 0000000..169666f --- /dev/null +++ b/tests/channel_sync.rs @@ -0,0 +1,46 @@ +#[cfg(test)] +#[cfg(feature = "channel")] +mod tests { + use rspc::transport::{channel, ClientTransporter, ServerTransporter}; + + pub struct MyStruct { + my_vec: Vec, + } + + #[rspc::service] + impl MyStruct { + pub fn len(&self) -> usize { + self.my_vec.len() + } + + pub fn push(&mut self, val: String) { + self.my_vec.push(val) + } + + pub fn pop(&mut self) -> Option { + self.my_vec.pop() + } + } + + #[tokio::test] + async fn test() { + let my_data = MyStruct { my_vec: Vec::new() }; + let (c, s) = channel::new_sync(); + + let srv_thread = tokio::spawn(async move { + let mut server = MyStructServer::from(my_data); + server.listen(s).await + }); + + let client = MyStructClient::new(c); + assert_eq!(client.len().await.unwrap(), 0); + client.push("Hello world!".to_string()).await.unwrap(); + assert_eq!(client.len().await.unwrap(), 1); + assert_eq!( + client.pop().await.unwrap(), + Some("Hello world!".to_string()) + ); + client.stop().await.unwrap(); + srv_thread.await.unwrap().unwrap(); + } +} diff --git a/example/Cargo.toml b/utilities/Cargo.toml similarity index 61% rename from example/Cargo.toml rename to utilities/Cargo.toml index fb9e5d4..e7e8bd0 100644 --- a/example/Cargo.toml +++ b/utilities/Cargo.toml @@ -1,13 +1,12 @@ [package] -name = "rspc_example" +name = "rspc_dev_utilities" version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -anyhow = "1.0.86" -async-std = "1.12.0" rspc = { path = ".." } -serde = "1.0.203" -tokio = "1.38.0" +serde = { version = "1.0", features = ["derive"] } +async-std = "1.12.0" +tokio = { version = "1.0", features = ["full"] } diff --git a/utilities/src/lib.rs b/utilities/src/lib.rs new file mode 100644 index 0000000..363a59f --- /dev/null +++ b/utilities/src/lib.rs @@ -0,0 +1 @@ +pub mod test_data; diff --git a/example/src/data.rs b/utilities/src/test_data.rs similarity index 89% rename from example/src/data.rs rename to utilities/src/test_data.rs index 0163335..ea5ce4e 100644 --- a/example/src/data.rs +++ b/utilities/src/test_data.rs @@ -1,8 +1,8 @@ use std::time::Duration; -use serde::{Deserialize, Serialize}; +use rspc::transport::{ClientTransporter, ServerTransporter}; -pub type RetData = (usize, Option); +use serde::{Deserialize, Serialize}; pub fn dur_to_num(dur: Duration) -> (u128, &'static str) { if dur.as_nanos() < 10000 { @@ -21,14 +21,6 @@ pub fn dur_to_str(dur: Duration) -> String { n.to_string() + " " + s } -pub fn process_data(dat: TestData) -> RetData { - (dat.len(), dat.calc()) -} - -pub fn process_data_ref(dat: &TestData) -> RetData { - (dat.len(), dat.calc()) -} - pub const DATASIZE: usize = 1000000; const TEST_STRINGS: [&str; 4] = ["toto", "tata", "titi", "tutu"]; @@ -45,8 +37,6 @@ pub struct TestData { vec: Vec<(bool, TestEnum)>, } -use crate::transport::{ClientTransporter, ServerTransporter}; - #[rspc::service] impl TestData { pub fn len(&self) -> usize {