Make client immutable to allow for async WASM

This commit is contained in:
NGnius (Graham) 2023-06-28 22:20:45 -04:00
parent 7aaa4ff88c
commit 4a00284a85
10 changed files with 275 additions and 240 deletions

317
Cargo.lock generated
View file

@ -3,10 +3,25 @@
version = 3 version = 3
[[package]] [[package]]
name = "anyhow" name = "addr2line"
version = "1.0.70" version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4" checksum = "a76fd60b23679b7d19bd066031410fb7e458ccc5e958eb5c325888ce4baedc97"
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.71"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8"
[[package]] [[package]]
name = "async-trait" name = "async-trait"
@ -16,7 +31,7 @@ checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.15", "syn 2.0.22",
] ]
[[package]] [[package]]
@ -25,6 +40,21 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "backtrace"
version = "0.3.67"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "233d376d6d185f2a3093e58f283f60f880315b6c60075b01f36b3b85154564ca"
dependencies = [
"addr2line",
"cc",
"cfg-if",
"libc",
"miniz_oxide",
"object",
"rustc-demangle",
]
[[package]] [[package]]
name = "beef" name = "beef"
version = "0.5.2" version = "0.5.2"
@ -69,7 +99,7 @@ checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a"
dependencies = [ dependencies = [
"errno-dragonfly", "errno-dragonfly",
"libc", "libc",
"windows-sys 0.48.0", "windows-sys",
] ]
[[package]] [[package]]
@ -103,6 +133,12 @@ version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "gimli"
version = "0.27.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e"
[[package]] [[package]]
name = "hashbrown" name = "hashbrown"
version = "0.12.3" version = "0.12.3"
@ -151,13 +187,13 @@ dependencies = [
[[package]] [[package]]
name = "io-lifetimes" name = "io-lifetimes"
version = "1.0.10" version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c66c74d2ae7e79a5a8f7ac924adbe38ee42a859c6539ad869eb51f0b52dc220" checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2"
dependencies = [ dependencies = [
"hermit-abi 0.3.1", "hermit-abi 0.3.1",
"libc", "libc",
"windows-sys 0.48.0", "windows-sys",
] ]
[[package]] [[package]]
@ -177,21 +213,21 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.141" version = "0.2.147"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5" checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3"
[[package]] [[package]]
name = "linux-raw-sys" name = "linux-raw-sys"
version = "0.3.1" version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d59d8c75012853d2e872fb56bc8a2e53718e2cafe1a4c823143141c6d90c322f" checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519"
[[package]] [[package]]
name = "lock_api" name = "lock_api"
version = "0.4.9" version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"scopeguard", "scopeguard",
@ -199,12 +235,9 @@ dependencies = [
[[package]] [[package]]
name = "log" name = "log"
version = "0.4.17" version = "0.4.19"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4"
dependencies = [
"cfg-if",
]
[[package]] [[package]]
name = "logos" name = "logos"
@ -225,8 +258,8 @@ dependencies = [
"fnv", "fnv",
"proc-macro2", "proc-macro2",
"quote", "quote",
"regex-syntax", "regex-syntax 0.6.29",
"syn 2.0.15", "syn 2.0.22",
] ]
[[package]] [[package]]
@ -239,10 +272,16 @@ dependencies = [
] ]
[[package]] [[package]]
name = "miette" name = "memchr"
version = "5.7.0" version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7abdc09c381c9336b9f2e9bd6067a9a5290d20e2d2e2296f275456121c33ae89" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
[[package]]
name = "miette"
version = "5.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a236ff270093b0b67451bc50a509bd1bad302cb1d3c7d37d5efe931238581fa9"
dependencies = [ dependencies = [
"miette-derive", "miette-derive",
"once_cell", "once_cell",
@ -252,25 +291,33 @@ dependencies = [
[[package]] [[package]]
name = "miette-derive" name = "miette-derive"
version = "5.7.0" version = "5.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8842972f23939443013dfd3720f46772b743e86f1a81d120d4b6fb090f87de1c" checksum = "4901771e1d44ddb37964565c654a3223ba41a594d02b8da471cc4464912b5cfa"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.15", "syn 2.0.22",
]
[[package]]
name = "miniz_oxide"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa"
dependencies = [
"adler",
] ]
[[package]] [[package]]
name = "mio" name = "mio"
version = "0.8.6" version = "0.8.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9" checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2"
dependencies = [ dependencies = [
"libc", "libc",
"log",
"wasi", "wasi",
"windows-sys 0.45.0", "windows-sys",
] ]
[[package]] [[package]]
@ -281,7 +328,7 @@ checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a"
[[package]] [[package]]
name = "nrpc" name = "nrpc"
version = "0.6.0" version = "0.7.0"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"bytes", "bytes",
@ -293,13 +340,13 @@ name = "nrpc-build"
version = "0.7.0" version = "0.7.0"
dependencies = [ dependencies = [
"nrpc", "nrpc",
"prettyplease 0.2.4", "prettyplease 0.2.9",
"proc-macro2", "proc-macro2",
"prost-build", "prost-build",
"prost-types", "prost-types",
"protox", "protox",
"quote", "quote",
"syn 2.0.15", "syn 2.0.22",
] ]
[[package]] [[package]]
@ -325,10 +372,19 @@ dependencies = [
] ]
[[package]] [[package]]
name = "once_cell" name = "object"
version = "1.17.1" version = "0.30.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" checksum = "03b4680b86d9cfafba8fc491dc9b6df26b68cf40e9e6cd73909194759a63c385"
dependencies = [
"memchr",
]
[[package]]
name = "once_cell"
version = "1.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
[[package]] [[package]]
name = "parking_lot" name = "parking_lot"
@ -342,15 +398,15 @@ dependencies = [
[[package]] [[package]]
name = "parking_lot_core" name = "parking_lot_core"
version = "0.9.7" version = "0.9.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"libc", "libc",
"redox_syscall 0.2.16", "redox_syscall",
"smallvec", "smallvec",
"windows-sys 0.45.0", "windows-targets",
] ]
[[package]] [[package]]
@ -381,19 +437,19 @@ dependencies = [
[[package]] [[package]]
name = "prettyplease" name = "prettyplease"
version = "0.2.4" version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ceca8aaf45b5c46ec7ed39fff75f57290368c1846d33d24a122ca81416ab058" checksum = "9825a04601d60621feed79c4e6b56d65db77cdca55cef43b46b0de1096d1c282"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"syn 2.0.15", "syn 2.0.22",
] ]
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.56" version = "1.0.63"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" checksum = "7b368fba921b0dce7e60f5e04ec15e565b3303972b42bcfde1d0713b881959eb"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
@ -445,9 +501,9 @@ dependencies = [
[[package]] [[package]]
name = "prost-reflect" name = "prost-reflect"
version = "0.11.3" version = "0.11.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4df26814fb2cd59b1764305047aac8e9c467efe84a9e51bfd0c8811f08fe88a" checksum = "000e1e05ebf7b26e1eba298e66fe4eee6eb19c567d0ffb35e0dd34231cdac4c8"
dependencies = [ dependencies = [
"logos", "logos",
"miette", "miette",
@ -467,9 +523,9 @@ dependencies = [
[[package]] [[package]]
name = "protox" name = "protox"
version = "0.3.1" version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5cb2d1d74977bfa8fc4ddac1951ea639197c2896a830b6c5640085e498726da2" checksum = "24022a7eb88547eaba87a1db7954c9c4cb4a143565c4e8f2b7f3e76eed63db2d"
dependencies = [ dependencies = [
"bytes", "bytes",
"miette", "miette",
@ -482,9 +538,9 @@ dependencies = [
[[package]] [[package]]
name = "protox-parse" name = "protox-parse"
version = "0.3.2" version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df78235a8c28dc4c5d8acb498d3000851b61b80a68774ff7b43323371b082ea4" checksum = "712a2a651fa4466e67df6c967df5d7fc6cbffac89afc7b834f97ec49846c9c11"
dependencies = [ dependencies = [
"logos", "logos",
"miette", "miette",
@ -494,22 +550,13 @@ dependencies = [
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.26" version = "1.0.28"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488"
dependencies = [ dependencies = [
"proc-macro2", "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]] [[package]]
name = "redox_syscall" name = "redox_syscall"
version = "0.3.5" version = "0.3.5"
@ -521,11 +568,11 @@ dependencies = [
[[package]] [[package]]
name = "regex" name = "regex"
version = "1.7.3" version = "1.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b1f693b24f6ac912f4893ef08244d70b6067480d2f1a46e950c9691e6749d1d" checksum = "d0ab3ca65655bb1e41f2a8c8cd662eb4fb035e67c3f78da1d61dffe89d07300f"
dependencies = [ dependencies = [
"regex-syntax", "regex-syntax 0.7.2",
] ]
[[package]] [[package]]
@ -535,17 +582,29 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
[[package]] [[package]]
name = "rustix" name = "regex-syntax"
version = "0.37.11" version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85597d61f83914ddeba6a47b3b8ffe7365107221c2e557ed94426489fefb5f77" checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78"
[[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.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b96e891d04aa506a6d1f318d2771bcb1c7dfda84e126660ace067c9b474bb2c0"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"errno", "errno",
"io-lifetimes", "io-lifetimes",
"libc", "libc",
"linux-raw-sys", "linux-raw-sys",
"windows-sys 0.48.0", "windows-sys",
] ]
[[package]] [[package]]
@ -592,9 +651,9 @@ dependencies = [
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.15" version = "2.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822" checksum = "2efbeae7acf4eabd6bcdcbd11c92f45231ddda7539edc7806bd1a04a03b24616"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -603,15 +662,16 @@ dependencies = [
[[package]] [[package]]
name = "tempfile" name = "tempfile"
version = "3.5.0" version = "3.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9fbec84f381d5795b08656e4912bec604d162bff9291d6189a78f4c8ab87998" checksum = "31c0432476357e58790aaa47a8efb0c5138f137343f3b5f23bd36a27e3b0a6d6"
dependencies = [ dependencies = [
"autocfg",
"cfg-if", "cfg-if",
"fastrand", "fastrand",
"redox_syscall 0.3.5", "redox_syscall",
"rustix", "rustix",
"windows-sys 0.45.0", "windows-sys",
] ]
[[package]] [[package]]
@ -631,16 +691,17 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.15", "syn 2.0.22",
] ]
[[package]] [[package]]
name = "tokio" name = "tokio"
version = "1.27.0" version = "1.29.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0de47a4eecbe11f498978a9b29d792f0d2692d1dd003650c24c76510e3bc001" checksum = "374442f06ee49c3a28a8fc9f01a2596fed7559c6b99b31279c3261778e77d84f"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"backtrace",
"bytes", "bytes",
"libc", "libc",
"mio", "mio",
@ -650,25 +711,25 @@ dependencies = [
"signal-hook-registry", "signal-hook-registry",
"socket2", "socket2",
"tokio-macros", "tokio-macros",
"windows-sys 0.45.0", "windows-sys",
] ]
[[package]] [[package]]
name = "tokio-macros" name = "tokio-macros"
version = "2.0.0" version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61a573bdc87985e9d6ddeed1b3d864e8a302c847e40d647746df2f1de209d1ce" checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.15", "syn 2.0.22",
] ]
[[package]] [[package]]
name = "unicode-ident" name = "unicode-ident"
version = "1.0.8" version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0"
[[package]] [[package]]
name = "unicode-width" name = "unicode-width"
@ -715,132 +776,66 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-sys"
version = "0.45.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
dependencies = [
"windows-targets 0.42.2",
]
[[package]] [[package]]
name = "windows-sys" name = "windows-sys"
version = "0.48.0" version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
dependencies = [ dependencies = [
"windows-targets 0.48.0", "windows-targets",
] ]
[[package]] [[package]]
name = "windows-targets" name = "windows-targets"
version = "0.42.2" version = "0.48.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f"
dependencies = [ dependencies = [
"windows_aarch64_gnullvm 0.42.2", "windows_aarch64_gnullvm",
"windows_aarch64_msvc 0.42.2", "windows_aarch64_msvc",
"windows_i686_gnu 0.42.2", "windows_i686_gnu",
"windows_i686_msvc 0.42.2", "windows_i686_msvc",
"windows_x86_64_gnu 0.42.2", "windows_x86_64_gnu",
"windows_x86_64_gnullvm 0.42.2", "windows_x86_64_gnullvm",
"windows_x86_64_msvc 0.42.2", "windows_x86_64_msvc",
] ]
[[package]]
name = "windows-targets"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5"
dependencies = [
"windows_aarch64_gnullvm 0.48.0",
"windows_aarch64_msvc 0.48.0",
"windows_i686_gnu 0.48.0",
"windows_i686_msvc 0.48.0",
"windows_x86_64_gnu 0.48.0",
"windows_x86_64_gnullvm 0.48.0",
"windows_x86_64_msvc 0.48.0",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8"
[[package]] [[package]]
name = "windows_aarch64_gnullvm" name = "windows_aarch64_gnullvm"
version = "0.48.0" version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc"
[[package]]
name = "windows_aarch64_msvc"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43"
[[package]] [[package]]
name = "windows_aarch64_msvc" name = "windows_aarch64_msvc"
version = "0.48.0" version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3"
[[package]]
name = "windows_i686_gnu"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f"
[[package]] [[package]]
name = "windows_i686_gnu" name = "windows_i686_gnu"
version = "0.48.0" version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241"
[[package]]
name = "windows_i686_msvc"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060"
[[package]] [[package]]
name = "windows_i686_msvc" name = "windows_i686_msvc"
version = "0.48.0" version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00"
[[package]]
name = "windows_x86_64_gnu"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36"
[[package]] [[package]]
name = "windows_x86_64_gnu" name = "windows_x86_64_gnu"
version = "0.48.0" version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3"
[[package]] [[package]]
name = "windows_x86_64_gnullvm" name = "windows_x86_64_gnullvm"
version = "0.48.0" version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953"
[[package]]
name = "windows_x86_64_msvc"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0"
[[package]] [[package]]
name = "windows_x86_64_msvc" name = "windows_x86_64_msvc"
version = "0.48.0" version = "0.48.0"

View file

@ -21,4 +21,4 @@ quote = "1.0"
syn = "2.0" syn = "2.0"
proc-macro2 = "1.0" proc-macro2 = "1.0"
nrpc = { version = "0.6", path = "../nrpc" } nrpc = { version = "0.7", path = "../nrpc" }

View file

@ -1,6 +1,6 @@
use std::path::Path;
use std::convert::AsRef; use std::convert::AsRef;
use std::iter::IntoIterator; use std::iter::IntoIterator;
use std::path::Path;
use prost_build::Config; use prost_build::Config;
use prost_build::{Service, ServiceGenerator}; use prost_build::{Service, ServiceGenerator};
@ -19,7 +19,7 @@ pub struct Transpiler<'a> {
impl<'a> Transpiler<'a> { impl<'a> Transpiler<'a> {
pub fn new( pub fn new(
files: impl IntoIterator<Item = impl AsRef<Path>>, files: impl IntoIterator<Item = impl AsRef<Path>>,
includes: impl IntoIterator<Item = impl AsRef<Path>> includes: impl IntoIterator<Item = impl AsRef<Path>>,
) -> Result<Self, impl std::error::Error> { ) -> Result<Self, impl std::error::Error> {
let files: Vec<_> = files.into_iter().collect(); let files: Vec<_> = files.into_iter().collect();
for f in &files { for f in &files {
@ -35,19 +35,28 @@ impl<'a> Transpiler<'a> {
/// Generate client and server service implementations /// Generate client and server service implementations
pub fn generate_all(mut self) -> Self { pub fn generate_all(mut self) -> Self {
self.service_generator.add_service(super::ProtobufServiceGenerator::all(std::env::var("OUT_DIR").unwrap().into())); self.service_generator
.add_service(super::ProtobufServiceGenerator::all(
std::env::var("OUT_DIR").unwrap().into(),
));
self self
} }
/// Generate server services implementations /// Generate server services implementations
pub fn generate_server(mut self) -> Self { pub fn generate_server(mut self) -> Self {
self.service_generator.add_service(super::ProtobufServiceGenerator::server(std::env::var("OUT_DIR").unwrap().into())); self.service_generator
.add_service(super::ProtobufServiceGenerator::server(
std::env::var("OUT_DIR").unwrap().into(),
));
self self
} }
/// Generate client services implementations /// Generate client services implementations
pub fn generate_client(mut self) -> Self { pub fn generate_client(mut self) -> Self {
self.service_generator.add_service(super::ProtobufServiceGenerator::client(std::env::var("OUT_DIR").unwrap().into())); self.service_generator
.add_service(super::ProtobufServiceGenerator::client(
std::env::var("OUT_DIR").unwrap().into(),
));
self self
} }
@ -70,7 +79,10 @@ impl<'a> Transpiler<'a> {
for mut pp in self.preprocessors { for mut pp in self.preprocessors {
pp.process(&mut files, &mut generated); pp.process(&mut files, &mut generated);
} }
self.service_generator.add_service(PreprocessedCodeGenInjector { generated_str: generated }); self.service_generator
.add_service(PreprocessedCodeGenInjector {
generated_str: generated,
});
self.prost_config self.prost_config
.service_generator(Box::new(self.service_generator)) .service_generator(Box::new(self.service_generator))
@ -116,9 +128,10 @@ impl ServiceGenerator for MergedServiceGenerator {
/// Compile proto files into Rust with server and client implementations /// Compile proto files into Rust with server and client implementations
pub fn compile( pub fn compile(
files: impl IntoIterator<Item = impl AsRef<Path>>, files: impl IntoIterator<Item = impl AsRef<Path>>,
includes: impl IntoIterator<Item = impl AsRef<Path>> includes: impl IntoIterator<Item = impl AsRef<Path>>,
) { ) {
Transpiler::new(files, includes).unwrap() Transpiler::new(files, includes)
.unwrap()
.generate_all() .generate_all()
.transpile() .transpile()
.unwrap(); .unwrap();
@ -129,7 +142,8 @@ pub fn compile_clients(
files: impl IntoIterator<Item = impl AsRef<Path>>, files: impl IntoIterator<Item = impl AsRef<Path>>,
includes: impl IntoIterator<Item = impl AsRef<Path>>, includes: impl IntoIterator<Item = impl AsRef<Path>>,
) { ) {
Transpiler::new(files, includes).unwrap() Transpiler::new(files, includes)
.unwrap()
.generate_client() .generate_client()
.transpile() .transpile()
.unwrap(); .unwrap();
@ -140,7 +154,8 @@ pub fn compile_servers(
files: impl IntoIterator<Item = impl AsRef<Path>>, files: impl IntoIterator<Item = impl AsRef<Path>>,
includes: impl IntoIterator<Item = impl AsRef<Path>>, includes: impl IntoIterator<Item = impl AsRef<Path>>,
) { ) {
Transpiler::new(files, includes).unwrap() Transpiler::new(files, includes)
.unwrap()
.generate_server() .generate_server()
.transpile() .transpile()
.unwrap(); .unwrap();

View file

@ -3,7 +3,7 @@ mod preprocessor;
mod service_gen; mod service_gen;
mod token_gen_traits; mod token_gen_traits;
pub use builder::{compile, compile_servers, compile_clients, Transpiler}; pub use builder::{compile, compile_clients, compile_servers, Transpiler};
pub use preprocessor::Preprocessor; pub use preprocessor::Preprocessor;
pub(crate) use service_gen::ProtobufServiceGenerator; pub(crate) use service_gen::ProtobufServiceGenerator;
pub use token_gen_traits::{IServiceGenerator, IPreprocessor, AbstractImpl}; pub use token_gen_traits::{AbstractImpl, IPreprocessor, IServiceGenerator};

View file

@ -52,7 +52,8 @@ fn trait_methods_server(descriptors: &Vec<prost_build::Method>) -> proc_macro2::
let mut gen_method_match_arms = Vec::with_capacity(descriptors.len()); let mut gen_method_match_arms = Vec::with_capacity(descriptors.len());
for descriptor in descriptors { for descriptor in descriptors {
match (descriptor.client_streaming, descriptor.server_streaming) { match (descriptor.client_streaming, descriptor.server_streaming) {
(false, false) => { // no streaming; 1->1 (false, false) => {
// no streaming; 1->1
let input_ty = quote::format_ident!("{}", descriptor.input_type); let input_ty = quote::format_ident!("{}", descriptor.input_type);
let output_ty = quote::format_ident!("{}", descriptor.output_type); let output_ty = quote::format_ident!("{}", descriptor.output_type);
let fn_name = quote::format_ident!("{}", descriptor.name); let fn_name = quote::format_ident!("{}", descriptor.name);
@ -63,25 +64,25 @@ fn trait_methods_server(descriptors: &Vec<prost_build::Method>) -> proc_macro2::
} }
); );
gen_method_match_arms.push( gen_method_match_arms.push(quote! {
quote! {
#method_name => { #method_name => {
Ok(self.#fn_name(#input_ty::decode(payload)?).await?.encode(buffer)?) Ok(self.#fn_name(#input_ty::decode(payload)?).await?.encode(buffer)?)
} }
});
} }
); (true, false) => {
}, // client streaming; 1 -> many
(true, false) => { // client streaming; 1 -> many
todo!("streaming not supported")
},
(false, true) => { // server streaming; many -> 1
todo!("streaming not supported") todo!("streaming not supported")
} }
(true, true) => { // all streaming; many -> many (false, true) => {
// server streaming; many -> 1
todo!("streaming not supported") todo!("streaming not supported")
},
} }
(true, true) => {
// all streaming; many -> many
todo!("streaming not supported")
}
}
} }
quote! { quote! {
@ -96,18 +97,23 @@ fn trait_methods_server(descriptors: &Vec<prost_build::Method>) -> proc_macro2::
} }
} }
fn struct_methods_client(package_name: &str, service_name: &str, descriptors: &Vec<prost_build::Method>) -> proc_macro2::TokenStream { fn struct_methods_client(
package_name: &str,
service_name: &str,
descriptors: &Vec<prost_build::Method>,
) -> proc_macro2::TokenStream {
let mut gen_methods = Vec::with_capacity(descriptors.len()); let mut gen_methods = Vec::with_capacity(descriptors.len());
for descriptor in descriptors { for descriptor in descriptors {
match (descriptor.client_streaming, descriptor.server_streaming) { match (descriptor.client_streaming, descriptor.server_streaming) {
(false, false) => { // no streaming; 1->1 (false, false) => {
// no streaming; 1->1
let input_ty = quote::format_ident!("{}", descriptor.input_type); let input_ty = quote::format_ident!("{}", descriptor.input_type);
let output_ty = quote::format_ident!("{}", descriptor.output_type); let output_ty = quote::format_ident!("{}", descriptor.output_type);
let fn_name = quote::format_ident!("{}", descriptor.name); let fn_name = quote::format_ident!("{}", descriptor.name);
let method_name = &descriptor.name; let method_name = &descriptor.name;
gen_methods.push( gen_methods.push(
quote! { quote! {
pub async fn #fn_name(&mut self, input: #input_ty) -> Result<#output_ty, ::nrpc::ServiceError> { pub async fn #fn_name(&self, input: #input_ty) -> Result<#output_ty, ::nrpc::ServiceError> {
let mut in_buf = ::nrpc::_helpers::bytes::BytesMut::new(); let mut in_buf = ::nrpc::_helpers::bytes::BytesMut::new();
input.encode(&mut in_buf)?; input.encode(&mut in_buf)?;
let mut out_buf = ::nrpc::_helpers::bytes::BytesMut::new(); let mut out_buf = ::nrpc::_helpers::bytes::BytesMut::new();
@ -116,18 +122,20 @@ fn struct_methods_client(package_name: &str, service_name: &str, descriptors: &V
} }
} }
); );
}, }
(true, false) => { // client streaming; 1 -> many (true, false) => {
todo!("streaming not supported") // client streaming; 1 -> many
},
(false, true) => { // server streaming; many -> 1
todo!("streaming not supported") todo!("streaming not supported")
} }
(true, true) => { // all streaming; many -> many (false, true) => {
// server streaming; many -> 1
todo!("streaming not supported") todo!("streaming not supported")
},
} }
(true, true) => {
// all streaming; many -> many
todo!("streaming not supported")
}
}
} }
quote! { quote! {
@ -143,20 +151,18 @@ fn generate_mod_rs(module_names: &Vec<String>, out_dir: &PathBuf) {
}); });
let gen_mods: syn::File = syn::parse2(quote! { let gen_mods: syn::File = syn::parse2(quote! {
#(#modules)* #(#modules)*
}).expect("invalid tokenstream"); })
.expect("invalid tokenstream");
let mod_str = prettyplease::unparse(&gen_mods); let mod_str = prettyplease::unparse(&gen_mods);
std::fs::write( std::fs::write(out_dir.join("mod.rs"), &mod_str).expect("Failed to write to $OUT_DIR/mod.rs");
out_dir
.join("mod.rs"),
&mod_str
).expect("Failed to write to $OUT_DIR/mod.rs");
//std::fs::write("/home/ngnius/potato.rs", &mod_str).unwrap(); //std::fs::write("/home/ngnius/potato.rs", &mod_str).unwrap();
} }
impl ServiceGenerator for ProtobufServiceGenerator { impl ServiceGenerator for ProtobufServiceGenerator {
fn generate(&mut self, service: Service, buf: &mut String) { fn generate(&mut self, service: Service, buf: &mut String) {
if self.generate_server { if self.generate_server {
let service_mod_name = quote::format_ident!("{}_mod_server", service.name.to_lowercase()); let service_mod_name =
quote::format_ident!("{}_mod_server", service.name.to_lowercase());
let service_trait_name = quote::format_ident!("{}Service", service.name); let service_trait_name = quote::format_ident!("{}Service", service.name);
let service_trait_methods = trait_methods_server(&service.methods); let service_trait_methods = trait_methods_server(&service.methods);
let service_struct_name = quote::format_ident!("{}ServiceImpl", service.name); let service_struct_name = quote::format_ident!("{}ServiceImpl", service.name);
@ -210,8 +216,10 @@ impl ServiceGenerator for ProtobufServiceGenerator {
buf.push_str(&code_str); buf.push_str(&code_str);
} }
if self.generate_client { if self.generate_client {
let service_mod_name = quote::format_ident!("{}_mod_client", service.name.to_lowercase()); let service_mod_name =
let service_methods = struct_methods_client(&service.package, &service.name, &service.methods); quote::format_ident!("{}_mod_client", service.name.to_lowercase());
let service_methods =
struct_methods_client(&service.package, &service.name, &service.methods);
let service_struct_name = quote::format_ident!("{}Service", service.name); let service_struct_name = quote::format_ident!("{}Service", service.name);
let descriptor_str = format!("{}.{}", service.package, service.name); let descriptor_str = format!("{}.{}", service.package, service.name);
let service_rename = quote::format_ident!("{}Client", service.name); let service_rename = quote::format_ident!("{}Client", service.name);

View file

@ -1,6 +1,6 @@
use proc_macro2::TokenStream;
use prost_build::Service; use prost_build::Service;
use prost_types::FileDescriptorSet; use prost_types::FileDescriptorSet;
use proc_macro2::TokenStream;
/// Higher-level abstraction of prost_build::ServiceGenerator /// Higher-level abstraction of prost_build::ServiceGenerator
pub trait IServiceGenerator { pub trait IServiceGenerator {
@ -33,7 +33,8 @@ impl<X> std::convert::From<X> for AbstractImpl<X> {
impl<X: IServiceGenerator> prost_build::ServiceGenerator for AbstractImpl<X> { impl<X: IServiceGenerator> prost_build::ServiceGenerator for AbstractImpl<X> {
fn generate(&mut self, service: Service, buf: &mut String) { fn generate(&mut self, service: Service, buf: &mut String) {
let gen_code: syn::File = syn::parse2(self.0.generate(service)).expect("invalid tokenstream"); let gen_code: syn::File =
syn::parse2(self.0.generate(service)).expect("invalid tokenstream");
let code_str = prettyplease::unparse(&gen_code); let code_str = prettyplease::unparse(&gen_code);
buf.push_str(&code_str); buf.push_str(&code_str);
} }

View file

@ -1,7 +1,7 @@
use std::error::Error; use std::error::Error;
use prost::Message;
use nrpc::ServerService; use nrpc::ServerService;
use prost::Message;
pub mod generated { pub mod generated {
include!(concat!(env!("OUT_DIR"), "/mod.rs")); include!(concat!(env!("OUT_DIR"), "/mod.rs"));
@ -22,7 +22,10 @@ async fn main() {
let mut input_buf = bytes::BytesMut::new(); let mut input_buf = bytes::BytesMut::new();
let mut output_buf = bytes::BytesMut::new(); let mut output_buf = bytes::BytesMut::new();
req.encode(&mut input_buf).unwrap(); req.encode(&mut input_buf).unwrap();
service_impl.call("say_hello", input_buf.into(), &mut output_buf).await.unwrap(); service_impl
.call("say_hello", input_buf.into(), &mut output_buf)
.await
.unwrap();
let actual_resp = helloworld::HelloReply::decode(output_buf).unwrap(); let actual_resp = helloworld::HelloReply::decode(output_buf).unwrap();
assert_eq!(resp, actual_resp); assert_eq!(resp, actual_resp);
@ -36,7 +39,10 @@ struct GreeterService;
#[async_trait::async_trait] #[async_trait::async_trait]
impl helloworld::IGreeter for GreeterService { impl helloworld::IGreeter for GreeterService {
async fn say_hello(&mut self, input: helloworld::HelloRequest) -> Result<helloworld::HelloReply, Box<dyn Error>> { async fn say_hello(
&mut self,
input: helloworld::HelloRequest,
) -> Result<helloworld::HelloReply, Box<dyn Error>> {
let result = helloworld::HelloReply { let result = helloworld::HelloReply {
message: format!("Hello {}", input.name), message: format!("Hello {}", input.name),
}; };
@ -49,16 +55,22 @@ struct ClientHandler;
#[async_trait::async_trait] #[async_trait::async_trait]
impl nrpc::ClientHandler for ClientHandler { impl nrpc::ClientHandler for ClientHandler {
async fn call(&mut self, async fn call(
&mut self,
package: &str, package: &str,
service: &str, service: &str,
method: &str, method: &str,
input: bytes::Bytes, input: bytes::Bytes,
output: &mut bytes::BytesMut) -> Result<(), nrpc::ServiceError> { output: &mut bytes::BytesMut,
println!("call {}.{}/{} with data {:?}", package, service, method, input); ) -> Result<(), nrpc::ServiceError> {
println!(
"call {}.{}/{} with data {:?}",
package, service, method, input
);
// This is ok to hardcode ONLY because it's for testing // This is ok to hardcode ONLY because it's for testing
Ok(helloworld::HelloReply { Ok(helloworld::HelloReply {
message: "Hello World".into(), message: "Hello World".into(),
}.encode(output)?) }
.encode(output)?)
} }
} }

View file

@ -1,6 +1,6 @@
[package] [package]
name = "nrpc" name = "nrpc"
version = "0.6.0" version = "0.7.0"
edition = "2021" edition = "2021"
license = "Apache-2.0" license = "Apache-2.0"
repository = "https://github.com/NGnius/nRPC" repository = "https://github.com/NGnius/nRPC"

View file

@ -1,6 +1,6 @@
mod service; mod service;
pub use service::{ServerService, ServiceError, ClientService, ClientHandler}; pub use service::{ClientHandler, ClientService, ServerService, ServiceError};
pub mod _helpers { pub mod _helpers {
pub use async_trait; pub use async_trait;

View file

@ -2,20 +2,24 @@
pub trait ServerService { pub trait ServerService {
fn descriptor(&self) -> &'static str; fn descriptor(&self) -> &'static str;
async fn call(&mut self, async fn call(
&mut self,
method: &str, method: &str,
input: bytes::Bytes, input: bytes::Bytes,
output: &mut bytes::BytesMut) -> Result<(), ServiceError>; output: &mut bytes::BytesMut,
) -> Result<(), ServiceError>;
} }
#[async_trait::async_trait] #[async_trait::async_trait]
pub trait ClientHandler { pub trait ClientHandler {
async fn call(&mut self, async fn call(
&self,
package: &str, package: &str,
service: &str, service: &str,
method: &str, method: &str,
input: bytes::Bytes, input: bytes::Bytes,
output: &mut bytes::BytesMut) -> Result<(), ServiceError>; output: &mut bytes::BytesMut,
) -> Result<(), ServiceError>;
} }
pub trait ClientService { pub trait ClientService {