From d2b170e2c9276f933657e167629c3dd3ab1961c0 Mon Sep 17 00:00:00 2001 From: MrRevillod Date: Fri, 24 Oct 2025 18:48:57 -0300 Subject: [PATCH 1/2] refactor: :fire: change the way to declare `providers` and improve the di example --- Cargo.lock | 739 +++++++++++++++++- examples/dependency-injection/.env | 4 + examples/dependency-injection/Cargo.toml | 4 +- examples/dependency-injection/README.md | 39 + examples/dependency-injection/compose.yaml | 20 + .../dependency-injection/config/config.toml | 5 +- .../migrations/20251024204317_tasks.sql | 6 + examples/dependency-injection/src/database.rs | 41 +- examples/dependency-injection/src/main.rs | 23 +- .../dependency-injection/src/middleware.rs | 10 +- .../dependency-injection/src/repository.rs | 31 +- examples/dependency-injection/src/service.rs | 20 - examples/middlewares/src/main.rs | 2 +- sword-macros/src/injectable/parse.rs | 25 +- sword-macros/src/lib.rs | 6 +- sword-tests/src/application/di.rs | 2 +- 16 files changed, 871 insertions(+), 106 deletions(-) create mode 100644 examples/dependency-injection/.env create mode 100644 examples/dependency-injection/README.md create mode 100644 examples/dependency-injection/compose.yaml create mode 100644 examples/dependency-injection/config/migrations/20251024204317_tasks.sql delete mode 100644 examples/dependency-injection/src/service.rs diff --git a/Cargo.lock b/Cargo.lock index 141b350..66eebc1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -72,6 +72,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "allocator-api2" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" + [[package]] name = "android_system_properties" version = "0.1.5" @@ -103,6 +109,15 @@ dependencies = [ "serde_json", ] +[[package]] +name = "atoi" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28d99ec8bfea296261ca1af174f24225171fea9664ba9003cbebee704810528" +dependencies = [ + "num-traits", +] + [[package]] name = "atomic-waker" version = "1.1.2" @@ -252,6 +267,12 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" +[[package]] +name = "base64ct" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55248b47b0caf0546f7988906588779981c43bb1bc9d0c44087278f80cdb44ba" + [[package]] name = "basic-server" version = "0.1.0" @@ -266,6 +287,9 @@ name = "bitflags" version = "2.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394" +dependencies = [ + "serde", +] [[package]] name = "bitvec" @@ -350,6 +374,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + [[package]] name = "bytes" version = "1.10.1" @@ -422,7 +452,7 @@ version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fde0e0ec90c9dfb3b4b1a0891a7dcd0e2bffde2f7efed5fe7c9bb00e5bfb915e" dependencies = [ - "windows-sys", + "windows-sys 0.59.0", ] [[package]] @@ -439,6 +469,15 @@ dependencies = [ "static_assertions", ] +[[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 = "config-file" version = "0.1.0" @@ -448,6 +487,12 @@ dependencies = [ "sword", ] +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + [[package]] name = "const_format" version = "0.2.35" @@ -509,6 +554,36 @@ dependencies = [ "libc", ] +[[package]] +name = "crc" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9710d3b3739c2e349eb44fe848ad0b7c8cb1e42bd87ee49371df2f7acaf3e675" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" + +[[package]] +name = "crossbeam-queue" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f58bbc28f91df819d0aa2a2c00cd19754769c2fad90579b3592b1c9ba7a3115" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" + [[package]] name = "crypto-common" version = "0.1.6" @@ -574,10 +649,21 @@ checksum = "2a2330da5de22e8a3cb63252ce2abb30116bf5265e89c0e01bc17015ce30a476" name = "dependency-injection" version = "0.1.0" dependencies = [ + "dotenv", "serde", - "serde_json", + "sqlx", "sword", - "tokio", +] + +[[package]] +name = "der" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" +dependencies = [ + "const-oid", + "pem-rfc7468", + "zeroize", ] [[package]] @@ -602,6 +688,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", + "const-oid", "crypto-common", "subtle", ] @@ -700,6 +787,27 @@ dependencies = [ "syn 2.0.106", ] +[[package]] +name = "dotenv" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" + +[[package]] +name = "dotenvy" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" + +[[package]] +name = "either" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" +dependencies = [ + "serde", +] + [[package]] name = "encoding_rs" version = "0.8.35" @@ -722,7 +830,29 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.61.1", +] + +[[package]] +name = "etcetera" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "136d1b5283a1ab77bd9257427ffd09d8667ced0570b6f938942bc7568ed5b943" +dependencies = [ + "cfg-if", + "home", + "windows-sys 0.48.0", +] + +[[package]] +name = "event-listener" +version = "5.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13b66accf52311f30a0db42147dadea9850cb48cd070028831ae5f5d4b856ab" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", ] [[package]] @@ -731,12 +861,29 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ced73b1dacfc750a6db6c0a0c3a3853c8b41997e2e2c563dc90804ae6867959" +[[package]] +name = "flume" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0e4dd2a88388a1f4ccc7c9ce104604dab68d9f408dc34cd45823d5a9069095" +dependencies = [ + "futures-core", + "futures-sink", + "spin", +] + [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + [[package]] name = "form_urlencoded" version = "1.2.2" @@ -794,6 +941,17 @@ dependencies = [ "futures-util", ] +[[package]] +name = "futures-intrusive" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d930c203dd0b6ff06e0201a4a2fe9149b43c684fd4420555b26d21b1a02956f" +dependencies = [ + "futures-core", + "lock_api", + "parking_lot", +] + [[package]] name = "futures-io" version = "0.3.31" @@ -941,12 +1099,38 @@ dependencies = [ "ahash", ] +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash", +] + [[package]] name = "hashbrown" version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d" +[[package]] +name = "hashlink" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7382cf6263419f2d8df38c55d7da83da5c18aef87fc7a7fc1fb1e344edfe14c1" +dependencies = [ + "hashbrown 0.15.5", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "helmet" version = "0.1.0" @@ -960,6 +1144,12 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77e5257ac01ab4aba4c6258f179f813a850f053b18224ca68d62c9d158947c11" +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + [[package]] name = "hkdf" version = "0.12.4" @@ -978,6 +1168,15 @@ dependencies = [ "digest", ] +[[package]] +name = "home" +version = "0.5.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc627f471c528ff0c4a49e1d5e60450c8f6461dd6d10ba9dcd3a61d3dff7728d" +dependencies = [ + "windows-sys 0.61.1", +] + [[package]] name = "hot-reload" version = "0.1.0" @@ -1268,6 +1467,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +dependencies = [ + "spin", +] + [[package]] name = "libc" version = "0.2.176" @@ -1284,6 +1492,33 @@ dependencies = [ "windows-link", ] +[[package]] +name = "libm" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de" + +[[package]] +name = "libredox" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "416f7e718bdb06000964960ffa43b4335ad4012ae8b99060261aa4a8088d5ccb" +dependencies = [ + "bitflags", + "libc", + "redox_syscall", +] + +[[package]] +name = "libsqlite3-sys" +version = "0.30.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e99fb7a497b1e3339bc746195567ed8d3e24945ecd636e3619d20b9de9e9149" +dependencies = [ + "pkg-config", + "vcpkg", +] + [[package]] name = "linux-raw-sys" version = "0.11.0" @@ -1324,6 +1559,16 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3" +[[package]] +name = "md-5" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" +dependencies = [ + "cfg-if", + "digest", +] + [[package]] name = "memchr" version = "2.7.6" @@ -1381,7 +1626,7 @@ checksum = "78bed444cc8a2160f01cbcf811ef18cac863ad68ae8ca62092e8db51d51c761c" dependencies = [ "libc", "wasi 0.11.1+wasi-snapshot-preview1", - "windows-sys", + "windows-sys 0.59.0", ] [[package]] @@ -1410,12 +1655,49 @@ dependencies = [ "sword", ] +[[package]] +name = "num-bigint-dig" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc84195820f291c7697304f3cbdadd1cb7199c0efc917ff5eafd71225c136151" +dependencies = [ + "byteorder", + "lazy_static", + "libm", + "num-integer", + "num-iter", + "num-traits", + "rand 0.8.5", + "smallvec", + "zeroize", +] + [[package]] name = "num-conv" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" +[[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-iter" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.19" @@ -1423,6 +1705,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", + "libm", ] [[package]] @@ -1446,6 +1729,12 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" +[[package]] +name = "parking" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" + [[package]] name = "parking_lot" version = "0.12.4" @@ -1466,7 +1755,16 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-targets", + "windows-targets 0.52.6", +] + +[[package]] +name = "pem-rfc7468" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" +dependencies = [ + "base64ct", ] [[package]] @@ -1507,6 +1805,33 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "pkcs1" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" +dependencies = [ + "der", + "pkcs8", + "spki", +] + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "pkg-config" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" + [[package]] name = "polyval" version = "0.6.2" @@ -1808,6 +2133,26 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "rsa" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78928ac1ed176a5ca1d17e578a1825f3d81ca54cf41053a592584b020cfd691b" +dependencies = [ + "const-oid", + "digest", + "num-bigint-dig", + "num-integer", + "num-traits", + "pkcs1", + "pkcs8", + "rand_core 0.6.4", + "signature", + "spki", + "subtle", + "zeroize", +] + [[package]] name = "rust-multipart-rfc7578_2" version = "0.8.0" @@ -1861,7 +2206,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.61.1", ] [[package]] @@ -2000,6 +2345,16 @@ dependencies = [ "libc", ] +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest", + "rand_core 0.6.4", +] + [[package]] name = "simdutf8" version = "0.1.5" @@ -2027,6 +2382,9 @@ name = "smallvec" version = "1.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" +dependencies = [ + "serde", +] [[package]] name = "socket2" @@ -2035,7 +2393,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "233504af464074f9d066d7b5416c5f9b894a5862a6506e306f7b816cdd6f1807" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.59.0", ] [[package]] @@ -2043,6 +2401,207 @@ name = "spin" version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "sqlx" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fefb893899429669dcdd979aff487bd78f4064e5e7907e4269081e0ef7d97dc" +dependencies = [ + "sqlx-core", + "sqlx-macros", + "sqlx-mysql", + "sqlx-postgres", + "sqlx-sqlite", +] + +[[package]] +name = "sqlx-core" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee6798b1838b6a0f69c007c133b8df5866302197e404e8b6ee8ed3e3a5e68dc6" +dependencies = [ + "base64", + "bytes", + "crc", + "crossbeam-queue", + "either", + "event-listener", + "futures-core", + "futures-intrusive", + "futures-io", + "futures-util", + "hashbrown 0.15.5", + "hashlink", + "indexmap", + "log", + "memchr", + "once_cell", + "percent-encoding", + "serde", + "serde_json", + "sha2", + "smallvec", + "thiserror", + "tokio", + "tokio-stream", + "tracing", + "url", +] + +[[package]] +name = "sqlx-macros" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2d452988ccaacfbf5e0bdbc348fb91d7c8af5bee192173ac3636b5fb6e6715d" +dependencies = [ + "proc-macro2", + "quote", + "sqlx-core", + "sqlx-macros-core", + "syn 2.0.106", +] + +[[package]] +name = "sqlx-macros-core" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19a9c1841124ac5a61741f96e1d9e2ec77424bf323962dd894bdb93f37d5219b" +dependencies = [ + "dotenvy", + "either", + "heck", + "hex", + "once_cell", + "proc-macro2", + "quote", + "serde", + "serde_json", + "sha2", + "sqlx-core", + "sqlx-mysql", + "sqlx-postgres", + "sqlx-sqlite", + "syn 2.0.106", + "tokio", + "url", +] + +[[package]] +name = "sqlx-mysql" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa003f0038df784eb8fecbbac13affe3da23b45194bd57dba231c8f48199c526" +dependencies = [ + "atoi", + "base64", + "bitflags", + "byteorder", + "bytes", + "crc", + "digest", + "dotenvy", + "either", + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "generic-array", + "hex", + "hkdf", + "hmac", + "itoa", + "log", + "md-5", + "memchr", + "once_cell", + "percent-encoding", + "rand 0.8.5", + "rsa", + "serde", + "sha1", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror", + "tracing", + "whoami", +] + +[[package]] +name = "sqlx-postgres" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db58fcd5a53cf07c184b154801ff91347e4c30d17a3562a635ff028ad5deda46" +dependencies = [ + "atoi", + "base64", + "bitflags", + "byteorder", + "crc", + "dotenvy", + "etcetera", + "futures-channel", + "futures-core", + "futures-util", + "hex", + "hkdf", + "hmac", + "home", + "itoa", + "log", + "md-5", + "memchr", + "once_cell", + "rand 0.8.5", + "serde", + "serde_json", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror", + "tracing", + "whoami", +] + +[[package]] +name = "sqlx-sqlite" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2d12fe70b2c1b4401038055f90f151b78208de1f9f89a7dbfd41587a10c3eea" +dependencies = [ + "atoi", + "flume", + "futures-channel", + "futures-core", + "futures-executor", + "futures-intrusive", + "futures-util", + "libsqlite3-sys", + "log", + "percent-encoding", + "serde", + "serde_urlencoded", + "sqlx-core", + "thiserror", + "tracing", + "url", +] [[package]] name = "stable_deref_trait" @@ -2056,6 +2615,17 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "stringprep" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4df3d392d81bd458a8a621b8bffbd2302a12ffe288a9d931670948749463b1" +dependencies = [ + "unicode-bidi", + "unicode-normalization", + "unicode-properties", +] + [[package]] name = "strsim" version = "0.11.1" @@ -2295,7 +2865,7 @@ dependencies = [ "slab", "socket2", "tokio-macros", - "windows-sys", + "windows-sys 0.59.0", ] [[package]] @@ -2309,6 +2879,17 @@ dependencies = [ "syn 2.0.106", ] +[[package]] +name = "tokio-stream" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eca58d7bba4a75707817a2c44174253f9236b2d5fbd055602e9d5c07c139a047" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "toml" version = "0.9.7" @@ -2493,12 +3074,33 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f" +[[package]] +name = "unicode-bidi" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c1cb5db39152898a79168971543b1cb5020dff7fe43c8dc468b0885f5e29df5" + [[package]] name = "unicode-ident" version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d" +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-properties" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e70f2a8b45122e719eb623c01822704c4e0907e7e426a05927e1a1cfff5b75d0" + [[package]] name = "unicode-xid" version = "0.2.6" @@ -2595,6 +3197,12 @@ dependencies = [ "syn 2.0.106", ] +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "version_check" version = "0.9.5" @@ -2656,6 +3264,12 @@ dependencies = [ "wit-bindgen", ] +[[package]] +name = "wasite" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" + [[package]] name = "wasm-bindgen" version = "0.2.104" @@ -2738,6 +3352,16 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "whoami" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d4a4db5077702ca3015d3d02d74974948aba2ad9e12ab7df718ee64ccd7e97d" +dependencies = [ + "libredox", + "wasite", +] + [[package]] name = "windows-core" version = "0.62.1" @@ -2797,13 +3421,46 @@ dependencies = [ "windows-link", ] +[[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.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.61.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f109e41dd4a3c848907eb83d5a42ea98b3769495597450cf6d153507b166f0f" +dependencies = [ + "windows-link", +] + +[[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]] @@ -2812,28 +3469,46 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] +[[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.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" +[[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.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" +[[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.6" @@ -2846,24 +3521,48 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" +[[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.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +[[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.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" +[[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.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" +[[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.6" @@ -2971,6 +3670,12 @@ dependencies = [ "synstructure", ] +[[package]] +name = "zeroize" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" + [[package]] name = "zerotrie" version = "0.2.2" diff --git a/examples/dependency-injection/.env b/examples/dependency-injection/.env new file mode 100644 index 0000000..d2cc117 --- /dev/null +++ b/examples/dependency-injection/.env @@ -0,0 +1,4 @@ +POSTGRES_USER=user +POSTGRES_PASSWORD=password +POSTGRES_DB=postgres_db +POSTGRES_DATABASE_URL="postgres://user:password@localhost:5432/postgres_db" \ No newline at end of file diff --git a/examples/dependency-injection/Cargo.toml b/examples/dependency-injection/Cargo.toml index 2de311b..92f7708 100644 --- a/examples/dependency-injection/Cargo.toml +++ b/examples/dependency-injection/Cargo.toml @@ -10,5 +10,5 @@ path = "src/main.rs" [dependencies] sword = { workspace = true } serde = { workspace = true } -serde_json = { workspace = true } -tokio = { workspace = true } +sqlx = { version = "0.8.6", features = ["postgres", "runtime-tokio"] } +dotenv = "0.15.0" diff --git a/examples/dependency-injection/README.md b/examples/dependency-injection/README.md new file mode 100644 index 0000000..8f5e613 --- /dev/null +++ b/examples/dependency-injection/README.md @@ -0,0 +1,39 @@ + +# Dependency injection example with SQLx + +To run this example, make sure you have Docker installed and running on your machine. + +## Setup + +1. Clone the Sword repository if you haven't already: + + ```bash + git clone https://github.com/sword-web/sword.git + cd sword/examples/dependency-injection + ``` + +2. Run the PostgreSQL database using Docker Compose: + + ```bash + docker-compose up -d + ``` + +3. Run the Sword application: + + ```bash + cargo run + ``` + +## Endpoints + +### List tasks + +```bash +curl http://localhost:8080/tasks +``` + +### Create a new task (with default values) + +```bash +curl -X POST http://localhost:8080/tasks +``` \ No newline at end of file diff --git a/examples/dependency-injection/compose.yaml b/examples/dependency-injection/compose.yaml new file mode 100644 index 0000000..422391a --- /dev/null +++ b/examples/dependency-injection/compose.yaml @@ -0,0 +1,20 @@ +version: '3.8' + +services: + postgres: + image: postgres:15 + env_file: + - "./.env" + container_name: sword_postgres_example + restart: unless-stopped + environment: + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + POSTGRES_DB: ${POSTGRES_DB} + ports: + - "5432:5432" + volumes: + - postgres_data:/var/lib/postgresql/data + +volumes: + postgres_data: \ No newline at end of file diff --git a/examples/dependency-injection/config/config.toml b/examples/dependency-injection/config/config.toml index 0cc6201..68a0c5d 100644 --- a/examples/dependency-injection/config/config.toml +++ b/examples/dependency-injection/config/config.toml @@ -4,7 +4,8 @@ port = 8080 body_limit = "10MB" request_timeout_seconds = 15 graceful_shutdown = false -name = "MySwordApp" +name = "Dependency Injection Example" [db-config] -collection_name = "tasks" +uri = "${POSTGRES_DATABASE_URL}" +migrations_path = "config/migrations" diff --git a/examples/dependency-injection/config/migrations/20251024204317_tasks.sql b/examples/dependency-injection/config/migrations/20251024204317_tasks.sql new file mode 100644 index 0000000..26d7805 --- /dev/null +++ b/examples/dependency-injection/config/migrations/20251024204317_tasks.sql @@ -0,0 +1,6 @@ +-- Add migration script here + +CREATE TABLE tasks( + id INT PRIMARY KEY, + title TEXT NOT NULL +) \ No newline at end of file diff --git a/examples/dependency-injection/src/database.rs b/examples/dependency-injection/src/database.rs index 8f18291..846257f 100644 --- a/examples/dependency-injection/src/database.rs +++ b/examples/dependency-injection/src/database.rs @@ -1,43 +1,42 @@ -use std::{collections::HashMap, sync::Arc}; +use std::{path::Path, sync::Arc}; use serde::Deserialize; -use serde_json::Value; +use sqlx::{migrate::Migrator, PgPool}; use sword::prelude::*; -use tokio::sync::RwLock; - -pub type Store = Arc>>>; #[derive(Clone, Deserialize)] #[config(key = "db-config")] pub struct DatabaseConfig { - collection_name: String, + uri: String, + migrations_path: String, } -#[injectable(kind = "provider")] +#[injectable(provider)] pub struct Database { - db: Store, + pool: Arc, } impl Database { pub async fn new(db_conf: DatabaseConfig) -> Self { - let db = Arc::new(RwLock::new(HashMap::new())); - - db.write().await.insert(db_conf.collection_name, Vec::new()); + let pool = PgPool::connect(&db_conf.uri) + .await + .expect("Failed to create Postgres connection pool"); - Self { db } - } + let migrator = Migrator::new(Path::new(&db_conf.migrations_path)) + .await + .unwrap(); - pub async fn insert(&self, table: &'static str, record: Value) { - let mut db = self.db.write().await; + migrator + .run(&pool) + .await + .expect("Failed to run database migrations"); - if let Some(table_data) = db.get_mut(table) { - table_data.push(record); + Self { + pool: Arc::new(pool), } } - pub async fn get_all(&self, table: &'static str) -> Option> { - let db = self.db.read().await; - - db.get(table).cloned() + pub fn get_pool(&self) -> &PgPool { + &self.pool } } diff --git a/examples/dependency-injection/src/main.rs b/examples/dependency-injection/src/main.rs index 3a6fe3d..24b5ac3 100644 --- a/examples/dependency-injection/src/main.rs +++ b/examples/dependency-injection/src/main.rs @@ -1,24 +1,23 @@ mod database; mod middleware; mod repository; -mod service; use std::sync::Arc; +use dotenv::dotenv; pub use middleware::MyMiddleware; pub use repository::TaskRepository; -use serde_json::json; use sword::{core::DependencyContainer, prelude::*}; use crate::{ database::{Database, DatabaseConfig}, - service::TasksService, + repository::Task, }; -#[controller("/tasks", version = "v1")] +#[controller("/tasks")] struct TasksController { - tasks: Arc, + tasks: Arc, } #[routes] @@ -33,12 +32,13 @@ impl TasksController { #[post("/")] async fn create_task(&self) -> HttpResponse { - let total_task = self.tasks.find_all().await.len(); + let tasks = self.tasks.find_all().await; + let total_count = tasks.len() as i32 + 1; - let task = json!({ - "id": total_task + 1, - "title": format!("Task {}", total_task + 1), - }); + let task = Task { + id: total_count, + title: format!("Task {total_count}"), + }; self.tasks.create(task.clone()).await; @@ -48,6 +48,8 @@ impl TasksController { #[sword::main] async fn main() { + dotenv().ok(); + let app = Application::builder(); let db_config = app.config::().unwrap(); @@ -56,7 +58,6 @@ async fn main() { let container = DependencyContainer::builder() .register_provider(db) .register_component::() - .register_component::() .build(); let app = app diff --git a/examples/dependency-injection/src/middleware.rs b/examples/dependency-injection/src/middleware.rs index e153a93..837051e 100644 --- a/examples/dependency-injection/src/middleware.rs +++ b/examples/dependency-injection/src/middleware.rs @@ -12,11 +12,15 @@ impl OnRequest for MyMiddleware { async fn on_request(&self, req: Request, next: Next) -> MiddlewareResult { let tasks = self.tasks_repository.find_all().await; + println!(); println!("Current tasks:"); - match tasks { - Some(tasks) => println!("{tasks:?}"), - None => println!("There's no tasks"), + if tasks.is_empty() { + println!("There's no tasks"); + } + + for task in tasks { + println!(" - [{}] {}", task.id, task.title); } next!(req, next) diff --git a/examples/dependency-injection/src/repository.rs b/examples/dependency-injection/src/repository.rs index 997e4d2..1f1e5fb 100644 --- a/examples/dependency-injection/src/repository.rs +++ b/examples/dependency-injection/src/repository.rs @@ -1,22 +1,35 @@ -use std::sync::Arc; - -use crate::database::{Database, DatabaseConfig}; -use serde_json::Value; +use crate::database::Database; +use serde::{Deserialize, Serialize}; +use sqlx::FromRow; +use std::sync::Arc; use sword::core::injectable; +#[derive(Clone, Serialize, Deserialize, FromRow)] +pub struct Task { + pub id: i32, + pub title: String, +} + #[injectable] pub struct TaskRepository { - db_conf: DatabaseConfig, db: Arc, } impl TaskRepository { - pub async fn create(&self, task: Value) { - self.db.insert("tasks", task).await; + pub async fn find_all(&self) -> Vec { + sqlx::query_as::<_, Task>("SELECT id, title FROM tasks") + .fetch_all(self.db.get_pool()) + .await + .expect("Failed to fetch tasks") } - pub async fn find_all(&self) -> Option> { - self.db.get_all("tasks").await + pub async fn create(&self, task: Task) { + sqlx::query("INSERT INTO tasks (id, title) VALUES ($1, $2)") + .bind(task.id) + .bind(task.title) + .execute(self.db.get_pool()) + .await + .expect("Failed to insert task"); } } diff --git a/examples/dependency-injection/src/service.rs b/examples/dependency-injection/src/service.rs deleted file mode 100644 index 32b179a..0000000 --- a/examples/dependency-injection/src/service.rs +++ /dev/null @@ -1,20 +0,0 @@ -use std::sync::Arc; - -use crate::TaskRepository; -use serde_json::Value; -use sword::core::injectable; - -#[injectable] -pub struct TasksService { - repository: Arc, -} - -impl TasksService { - pub async fn create(&self, task: Value) { - self.repository.create(task).await; - } - - pub async fn find_all(&self) -> Vec { - self.repository.find_all().await.unwrap_or_default() - } -} diff --git a/examples/middlewares/src/main.rs b/examples/middlewares/src/main.rs index 840c505..38e187c 100644 --- a/examples/middlewares/src/main.rs +++ b/examples/middlewares/src/main.rs @@ -75,7 +75,7 @@ impl TestController { } } -#[injectable(kind = "provider")] +#[injectable(provider)] pub struct Database { pub connection_string: String, } diff --git a/sword-macros/src/injectable/parse.rs b/sword-macros/src/injectable/parse.rs index 8fc77e2..f695502 100644 --- a/sword-macros/src/injectable/parse.rs +++ b/sword-macros/src/injectable/parse.rs @@ -1,7 +1,7 @@ use crate::shared::collect_struct_fields; use proc_macro::TokenStream; use syn::parse::{ParseStream, Result as ParseResult}; -use syn::{Ident, ItemStruct, LitStr, Token, Type, parse::Parse}; +use syn::{Ident, ItemStruct, Token, Type, parse::Parse}; pub enum InjectableKind { Provider, @@ -33,22 +33,15 @@ impl Parse for InjectableArgs { let arg: Ident = input.parse()?; match arg.to_string().as_str() { - "kind" => { - input.parse::()?; - let val: LitStr = input.parse()?; - kind = match val.value().as_str() { - "provider" => InjectableKind::Provider, - "component" => InjectableKind::Component, - _ => { - return Err(syn::Error::new_spanned( - val, - "Expected 'provider' or 'component'", - )); - } - }; - } + "provider" => kind = InjectableKind::Provider, + "component" => kind = InjectableKind::Component, "no_derive_clone" => derive_clone = false, - _ => return Err(syn::Error::new_spanned(arg, "Unknown attribute")), + _ => { + return Err(syn::Error::new_spanned( + arg, + "Unknown attribute. Use 'provider', 'component', or 'no_derive_clone'", + )); + } } if !input.is_empty() { diff --git a/sword-macros/src/lib.rs b/sword-macros/src/lib.rs index 20155cd..f90d464 100644 --- a/sword-macros/src/lib.rs +++ b/sword-macros/src/lib.rs @@ -310,7 +310,7 @@ pub fn config(attr: TokenStream, item: TokenStream) -> TokenStream { /// - `no_derive_clone`: (Optional) If provided, the struct will not derive the `Clone` automatically. /// By default, the struct will derive `Clone` if all its fields implement `Clone`. /// -/// ### Usage of `#[injectable]` without parameters +/// ### Usage of `#[injectable]` without parameters (same as #[injectable(component)]) /// /// ```rust,ignore /// #[injectable] @@ -329,10 +329,10 @@ pub fn config(attr: TokenStream, item: TokenStream) -> TokenStream { /// } /// ``` /// -/// ### Usage of `#[injectable(instance)]` with parameters +/// ### Usage of `#[injectable(provider)]` with parameters /// /// ```rust,ignore -/// #[injectable(kind = "provider")] +/// #[injectable(provider)] /// pub struct Database { /// db: Store, /// } diff --git a/sword-tests/src/application/di.rs b/sword-tests/src/application/di.rs index 54b6ca5..6cd7e95 100644 --- a/sword-tests/src/application/di.rs +++ b/sword-tests/src/application/di.rs @@ -9,7 +9,7 @@ use sword::prelude::*; pub type Store = Arc>>>; -#[injectable(kind = "provider")] +#[injectable(provider)] pub struct Database { db: Store, } From 809d548b02fda31fd63dc5282f705b25c11df066 Mon Sep 17 00:00:00 2001 From: MrRevillod Date: Fri, 24 Oct 2025 18:56:25 -0300 Subject: [PATCH 2/2] fix: :ambulance: remove unused dependencies reported by `machete` --- Cargo.lock | 26 -------------------------- examples/config-file/Cargo.toml | 1 - examples/middlewares/Cargo.toml | 1 - sword-tests/Cargo.toml | 5 ----- sword/Cargo.toml | 2 -- 5 files changed, 35 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 66eebc1..e4dc21b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -483,7 +483,6 @@ name = "config-file" version = "0.1.0" dependencies = [ "serde", - "serde_json", "sword", ] @@ -899,21 +898,6 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" -[[package]] -name = "futures" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - [[package]] name = "futures-channel" version = "0.3.31" @@ -987,7 +971,6 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" dependencies = [ - "futures-channel", "futures-core", "futures-io", "futures-macro", @@ -1597,7 +1580,6 @@ dependencies = [ name = "middlewares" version = "0.1.0" dependencies = [ - "axum", "serde", "serde_json", "sword", @@ -2693,8 +2675,6 @@ dependencies = [ "tower", "tower-cookies", "tower-http", - "tower-layer", - "tower-service", "validator", ] @@ -2713,17 +2693,12 @@ dependencies = [ name = "sword-tests" version = "0.1.3" dependencies = [ - "axum", "axum-test", - "futures", - "garde", "serde", "serde_json", "sword", "tokio", - "tower", "tower-http", - "uuid", "validator", ] @@ -3153,7 +3128,6 @@ version = "1.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2f87b8aa10b915a06587d0dec516c282ff295b475d94abf425d62b57710070a2" dependencies = [ - "getrandom 0.3.3", "js-sys", "wasm-bindgen", ] diff --git a/examples/config-file/Cargo.toml b/examples/config-file/Cargo.toml index ee7799e..1cb9403 100644 --- a/examples/config-file/Cargo.toml +++ b/examples/config-file/Cargo.toml @@ -6,4 +6,3 @@ edition = "2021" [dependencies] sword = { workspace = true } serde = { workspace = true } -serde_json = { workspace = true } diff --git a/examples/middlewares/Cargo.toml b/examples/middlewares/Cargo.toml index caad8c2..79f7796 100644 --- a/examples/middlewares/Cargo.toml +++ b/examples/middlewares/Cargo.toml @@ -7,4 +7,3 @@ edition = "2021" sword = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } -axum = { workspace = true } diff --git a/sword-tests/Cargo.toml b/sword-tests/Cargo.toml index 1d56483..77b022f 100644 --- a/sword-tests/Cargo.toml +++ b/sword-tests/Cargo.toml @@ -6,7 +6,6 @@ edition = "2024" publish = false [dependencies] -axum = "0.8.4" axum-test = "17.3.0" sword = { path = "../sword", features = [ @@ -22,8 +21,4 @@ serde = { version = "1.0.219", features = ["derive"] } validator = { version = "0.20.0", features = ["derive"] } serde_json = "1.0.140" -uuid = { version = "1.10.0", features = ["v4"] } -futures = "0.3" -garde.workspace = true -tower = { version = "0.5.2", features = ["timeout"] } tower-http = { workspace = true, features = ["cors", "timeout"] } diff --git a/sword/Cargo.toml b/sword/Cargo.toml index c157623..5723e4c 100644 --- a/sword/Cargo.toml +++ b/sword/Cargo.toml @@ -37,8 +37,6 @@ regex-lite = "0.1.7" validator = { workspace = true, optional = true } tower = "0.5.2" -tower-layer = "0.3.3" -tower-service = "0.3.3" tower-http = { version = "0.6.6", features = ["limit", "timeout"] } tower-cookies = { version = "0.11.0", optional = true } thiserror = "2.0.12"