From 1fe45583626a4c9c890cc01131d38c57f8728686 Mon Sep 17 00:00:00 2001 From: David Pedersen Date: Fri, 29 Apr 2022 18:53:41 +0200 Subject: [PATCH] Move examples to separate workspace (#978) * Move examples to separate workspace * update commands to run examples * remove debug --- .github/workflows/CI.yml | 21 +++++++++++-------- .gitignore | 3 ++- Cargo.toml | 1 - examples/Cargo.toml | 3 +++ examples/async-graphql/src/main.rs | 2 +- examples/chat/src/main.rs | 2 +- .../src/main.rs | 2 +- examples/cors/src/main.rs | 2 +- .../customize-extractor-error/src/main.rs | 2 +- examples/customize-path-rejection/src/main.rs | 2 +- .../src/main.rs | 2 +- examples/form/src/main.rs | 2 +- examples/global-404-handler/src/main.rs | 2 +- examples/graceful-shutdown/src/main.rs | 2 +- examples/hello-world/src/main.rs | 2 +- examples/key-value-store/src/main.rs | 2 +- examples/low-level-rustls/src/main.rs | 2 +- examples/multipart-form/src/main.rs | 2 +- examples/print-request-response/src/main.rs | 2 +- examples/prometheus-metrics/src/main.rs | 2 +- .../src/main.rs | 2 +- examples/readme/src/main.rs | 2 +- examples/reverse-proxy/src/main.rs | 2 +- .../src/main.rs | 2 +- examples/sessions/src/main.rs | 2 +- examples/sqlx-postgres/src/main.rs | 2 +- examples/sse/src/main.rs | 2 +- examples/static-file-server/src/main.rs | 2 +- examples/stream-to-file/src/main.rs | 2 +- examples/templates/src/main.rs | 2 +- examples/tls-rustls/src/main.rs | 2 +- examples/todos/src/main.rs | 2 +- examples/tokio-postgres/src/main.rs | 2 +- examples/tracing-aka-logging/src/main.rs | 2 +- examples/unix-domain-socket/src/main.rs | 2 +- examples/validator/src/main.rs | 2 +- examples/versioning/src/main.rs | 2 +- examples/websockets/src/main.rs | 2 +- 38 files changed, 51 insertions(+), 45 deletions(-) create mode 100644 examples/Cargo.toml diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index bf6d4266..a2c1f9fd 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -11,8 +11,12 @@ on: jobs: check: - # Run `cargo check` first to ensure that the pushed code at least compiles. runs-on: ubuntu-latest + strategy: + matrix: + pwd: + - . + - examples steps: - uses: actions/checkout@master - uses: actions-rs/toolchain@v1 @@ -23,15 +27,13 @@ jobs: components: clippy, rustfmt - uses: Swatinem/rust-cache@v1 - name: Check - uses: actions-rs/cargo@v1 - with: - command: clippy - args: --all --all-targets --all-features + working-directory: ${{ matrix.pwd }} + run: | + cargo clippy --all --all-targets --all-features - name: rustfmt - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check + working-directory: ${{ matrix.pwd }} + run: | + cargo fmt --all -- --check check-docs: runs-on: ubuntu-latest @@ -106,6 +108,7 @@ jobs: args: > -p axum -p axum-extra + -p axum-core --all-features --all-targets # the compiler errors are different on 1.54 which makes # the trybuild tests in axum-macros fail, so just run the doc diff --git a/.gitignore b/.gitignore index ad2f0ff1..7dace2a3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /target +/examples/target Cargo.lock -.DS_Store \ No newline at end of file +.DS_Store diff --git a/Cargo.toml b/Cargo.toml index 5120e29c..51b1cc39 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,5 +4,4 @@ members = [ "axum-core", "axum-extra", "axum-macros", - "examples/*", ] diff --git a/examples/Cargo.toml b/examples/Cargo.toml new file mode 100644 index 00000000..4f10fc34 --- /dev/null +++ b/examples/Cargo.toml @@ -0,0 +1,3 @@ +[workspace] +members = ["*"] +exclude = ["target"] diff --git a/examples/async-graphql/src/main.rs b/examples/async-graphql/src/main.rs index 9bc47a03..7d03d3b9 100644 --- a/examples/async-graphql/src/main.rs +++ b/examples/async-graphql/src/main.rs @@ -3,7 +3,7 @@ //! Run with //! //! ```not_rust -//! cargo run -p example-async-graphql +//! cd examples && cargo run -p example-async-graphql //! ``` mod starwars; diff --git a/examples/chat/src/main.rs b/examples/chat/src/main.rs index 6ad18669..5107323e 100644 --- a/examples/chat/src/main.rs +++ b/examples/chat/src/main.rs @@ -3,7 +3,7 @@ //! Run with //! //! ```not_rust -//! cargo run -p example-chat +//! cd examples && cargo run -p example-chat //! ``` use axum::{ diff --git a/examples/consume-body-in-extractor-or-middleware/src/main.rs b/examples/consume-body-in-extractor-or-middleware/src/main.rs index 9b4e42a3..1fdd9022 100644 --- a/examples/consume-body-in-extractor-or-middleware/src/main.rs +++ b/examples/consume-body-in-extractor-or-middleware/src/main.rs @@ -1,7 +1,7 @@ //! Run with //! //! ```not_rust -//! cargo run -p example-consume-body-in-extractor-or-middleware +//! cd examples && cargo run -p example-consume-body-in-extractor-or-middleware //! ``` use axum::{ diff --git a/examples/cors/src/main.rs b/examples/cors/src/main.rs index 939b49d4..e74258df 100644 --- a/examples/cors/src/main.rs +++ b/examples/cors/src/main.rs @@ -1,7 +1,7 @@ //! Run with //! //! ```not_rust -//! cargo run -p example-cors +//! cd examples && cargo run -p example-cors //! ``` use axum::{ diff --git a/examples/customize-extractor-error/src/main.rs b/examples/customize-extractor-error/src/main.rs index fcfd1726..bc0973b4 100644 --- a/examples/customize-extractor-error/src/main.rs +++ b/examples/customize-extractor-error/src/main.rs @@ -1,7 +1,7 @@ //! Run with //! //! ```not_rust -//! cargo run -p example-customize-extractor-error +//! cd examples && cargo run -p example-customize-extractor-error //! ``` use axum::{ diff --git a/examples/customize-path-rejection/src/main.rs b/examples/customize-path-rejection/src/main.rs index f78101f0..4e268949 100644 --- a/examples/customize-path-rejection/src/main.rs +++ b/examples/customize-path-rejection/src/main.rs @@ -1,7 +1,7 @@ //! Run with //! //! ```not_rust -//! cargo run -p example-customize-path-rejection +//! cd examples && cargo run -p example-customize-path-rejection //! ``` use axum::{ diff --git a/examples/error-handling-and-dependency-injection/src/main.rs b/examples/error-handling-and-dependency-injection/src/main.rs index b58c6432..d92b43bf 100644 --- a/examples/error-handling-and-dependency-injection/src/main.rs +++ b/examples/error-handling-and-dependency-injection/src/main.rs @@ -4,7 +4,7 @@ //! Run with //! //! ```not_rust -//! cargo run -p example-error-handling-and-dependency-injection +//! cd examples && cargo run -p example-error-handling-and-dependency-injection //! ``` use axum::{ diff --git a/examples/form/src/main.rs b/examples/form/src/main.rs index 6b11d0e6..7605baff 100644 --- a/examples/form/src/main.rs +++ b/examples/form/src/main.rs @@ -1,7 +1,7 @@ //! Run with //! //! ```not_rust -//! cargo run -p example-form +//! cd examples && cargo run -p example-form //! ``` use axum::{extract::Form, response::Html, routing::get, Router}; diff --git a/examples/global-404-handler/src/main.rs b/examples/global-404-handler/src/main.rs index 896f743f..385a0e21 100644 --- a/examples/global-404-handler/src/main.rs +++ b/examples/global-404-handler/src/main.rs @@ -1,7 +1,7 @@ //! Run with //! //! ```not_rust -//! cargo run -p example-global-404-handler +//! cd examples && cargo run -p example-global-404-handler //! ``` use axum::{ diff --git a/examples/graceful-shutdown/src/main.rs b/examples/graceful-shutdown/src/main.rs index 3704889a..f4a0fc29 100644 --- a/examples/graceful-shutdown/src/main.rs +++ b/examples/graceful-shutdown/src/main.rs @@ -1,7 +1,7 @@ //! Run with //! //! ```not_rust -//! cargo run -p example-graceful-shutdown +//! cd examples && cargo run -p example-graceful-shutdown //! kill or ctrl-c //! ``` diff --git a/examples/hello-world/src/main.rs b/examples/hello-world/src/main.rs index 466caceb..ed115f6b 100644 --- a/examples/hello-world/src/main.rs +++ b/examples/hello-world/src/main.rs @@ -1,7 +1,7 @@ //! Run with //! //! ```not_rust -//! cargo run -p example-hello-world +//! cd examples && cargo run -p example-hello-world //! ``` use axum::{response::Html, routing::get, Router}; diff --git a/examples/key-value-store/src/main.rs b/examples/key-value-store/src/main.rs index 649e25c2..0ad5b7f6 100644 --- a/examples/key-value-store/src/main.rs +++ b/examples/key-value-store/src/main.rs @@ -3,7 +3,7 @@ //! Run with: //! //! ```not_rust -//! cargo run -p example-key-value-store +//! cd examples && cargo run -p example-key-value-store //! ``` use axum::{ diff --git a/examples/low-level-rustls/src/main.rs b/examples/low-level-rustls/src/main.rs index 103cbcfc..1a077874 100644 --- a/examples/low-level-rustls/src/main.rs +++ b/examples/low-level-rustls/src/main.rs @@ -1,7 +1,7 @@ //! Run with //! //! ```not_rust -//! cargo run -p example-low-level-rustls +//! cd examples && cargo run -p example-low-level-rustls //! ``` use axum::{extract::ConnectInfo, routing::get, Router}; diff --git a/examples/multipart-form/src/main.rs b/examples/multipart-form/src/main.rs index 87e70cc1..7c6c1410 100644 --- a/examples/multipart-form/src/main.rs +++ b/examples/multipart-form/src/main.rs @@ -1,7 +1,7 @@ //! Run with //! //! ```not_rust -//! cargo run -p example-multipart-form +//! cd examples && cargo run -p example-multipart-form //! ``` use axum::{ diff --git a/examples/print-request-response/src/main.rs b/examples/print-request-response/src/main.rs index 3357579f..59c609dd 100644 --- a/examples/print-request-response/src/main.rs +++ b/examples/print-request-response/src/main.rs @@ -1,7 +1,7 @@ //! Run with //! //! ```not_rust -//! cargo run -p example-print-request-response +//! cd examples && cargo run -p example-print-request-response //! ``` use axum::{ diff --git a/examples/prometheus-metrics/src/main.rs b/examples/prometheus-metrics/src/main.rs index fc58882f..1152b3c7 100644 --- a/examples/prometheus-metrics/src/main.rs +++ b/examples/prometheus-metrics/src/main.rs @@ -4,7 +4,7 @@ //! Run with //! //! ```not_rust -//! cargo run -p example-prometheus-metrics +//! cd examples && cargo run -p example-prometheus-metrics //! ``` use axum::{ diff --git a/examples/query-params-with-empty-strings/src/main.rs b/examples/query-params-with-empty-strings/src/main.rs index aa424643..0af20111 100644 --- a/examples/query-params-with-empty-strings/src/main.rs +++ b/examples/query-params-with-empty-strings/src/main.rs @@ -1,7 +1,7 @@ //! Run with //! //! ```not_rust -//! cargo run -p example-query-params-with-empty-strings +//! cd examples && cargo run -p example-query-params-with-empty-strings //! ``` use axum::{extract::Query, routing::get, Router}; diff --git a/examples/readme/src/main.rs b/examples/readme/src/main.rs index bdcb8945..a606893d 100644 --- a/examples/readme/src/main.rs +++ b/examples/readme/src/main.rs @@ -1,7 +1,7 @@ //! Run with //! //! ```not_rust -//! cargo run -p example-readme +//! cd examples && cargo run -p example-readme //! ``` use axum::{ diff --git a/examples/reverse-proxy/src/main.rs b/examples/reverse-proxy/src/main.rs index ab551e5b..849af0b3 100644 --- a/examples/reverse-proxy/src/main.rs +++ b/examples/reverse-proxy/src/main.rs @@ -4,7 +4,7 @@ //! Run with //! //! ```not_rust -//! cargo run -p example-reverse-proxy +//! cd examples && cargo run -p example-reverse-proxy //! ``` use axum::{ diff --git a/examples/routes-and-handlers-close-together/src/main.rs b/examples/routes-and-handlers-close-together/src/main.rs index d2940930..5e52ad7b 100644 --- a/examples/routes-and-handlers-close-together/src/main.rs +++ b/examples/routes-and-handlers-close-together/src/main.rs @@ -1,7 +1,7 @@ //! Run with //! //! ```not_rust -//! cargo run -p example-routes-and-handlers-close-together +//! cd examples && cargo run -p example-routes-and-handlers-close-together //! ``` use axum::{ diff --git a/examples/sessions/src/main.rs b/examples/sessions/src/main.rs index 079c0dc2..3251122c 100644 --- a/examples/sessions/src/main.rs +++ b/examples/sessions/src/main.rs @@ -1,7 +1,7 @@ //! Run with //! //! ```not_rust -//! cargo run -p example-sessions +//! cd examples && cargo run -p example-sessions //! ``` use async_session::{MemoryStore, Session, SessionStore as _}; diff --git a/examples/sqlx-postgres/src/main.rs b/examples/sqlx-postgres/src/main.rs index 3e8f0525..9d101618 100644 --- a/examples/sqlx-postgres/src/main.rs +++ b/examples/sqlx-postgres/src/main.rs @@ -3,7 +3,7 @@ //! Run with //! //! ```not_rust -//! cargo run -p example-sqlx-postgres +//! cd examples && cargo run -p example-sqlx-postgres //! ``` //! //! Test with curl: diff --git a/examples/sse/src/main.rs b/examples/sse/src/main.rs index 2bcab4c5..d80f6685 100644 --- a/examples/sse/src/main.rs +++ b/examples/sse/src/main.rs @@ -1,7 +1,7 @@ //! Run with //! //! ```not_rust -//! cargo run -p example-sse +//! cd examples && cargo run -p example-sse //! ``` use axum::{ diff --git a/examples/static-file-server/src/main.rs b/examples/static-file-server/src/main.rs index 7e1034ba..fad45206 100644 --- a/examples/static-file-server/src/main.rs +++ b/examples/static-file-server/src/main.rs @@ -1,7 +1,7 @@ //! Run with //! //! ```not_rust -//! cargo run -p example-static-file-server +//! cd examples && cargo run -p example-static-file-server //! ``` use axum::{http::StatusCode, routing::get_service, Router}; diff --git a/examples/stream-to-file/src/main.rs b/examples/stream-to-file/src/main.rs index 6a8bad95..407d379d 100644 --- a/examples/stream-to-file/src/main.rs +++ b/examples/stream-to-file/src/main.rs @@ -1,7 +1,7 @@ //! Run with //! //! ```not_rust -//! cargo run -p example-stream-to-file +//! cd examples && cargo run -p example-stream-to-file //! ``` use axum::{ diff --git a/examples/templates/src/main.rs b/examples/templates/src/main.rs index ec47a083..90ea206b 100644 --- a/examples/templates/src/main.rs +++ b/examples/templates/src/main.rs @@ -1,7 +1,7 @@ //! Run with //! //! ```not_rust -//! cargo run -p example-templates +//! cd examples && cargo run -p example-templates //! ``` use askama::Template; diff --git a/examples/tls-rustls/src/main.rs b/examples/tls-rustls/src/main.rs index 862fca22..18f74cb3 100644 --- a/examples/tls-rustls/src/main.rs +++ b/examples/tls-rustls/src/main.rs @@ -1,7 +1,7 @@ //! Run with //! //! ```not_rust -//! cargo run -p example-tls-rustls +//! cd examples && cargo run -p example-tls-rustls //! ``` use axum::{routing::get, Router}; diff --git a/examples/todos/src/main.rs b/examples/todos/src/main.rs index c4fd3ddd..9a33416b 100644 --- a/examples/todos/src/main.rs +++ b/examples/todos/src/main.rs @@ -10,7 +10,7 @@ //! Run with //! //! ```not_rust -//! cargo run -p example-todos +//! cd examples && cargo run -p example-todos //! ``` use axum::{ diff --git a/examples/tokio-postgres/src/main.rs b/examples/tokio-postgres/src/main.rs index 2abac5ba..4489f616 100644 --- a/examples/tokio-postgres/src/main.rs +++ b/examples/tokio-postgres/src/main.rs @@ -1,7 +1,7 @@ //! Run with //! //! ```not_rust -//! cargo run -p example-tokio-postgres +//! cd examples && cargo run -p example-tokio-postgres //! ``` use axum::{ diff --git a/examples/tracing-aka-logging/src/main.rs b/examples/tracing-aka-logging/src/main.rs index edce1635..8da6e5fe 100644 --- a/examples/tracing-aka-logging/src/main.rs +++ b/examples/tracing-aka-logging/src/main.rs @@ -1,7 +1,7 @@ //! Run with //! //! ```not_rust -//! cargo run -p example-tracing-aka-logging +//! cd examples && cargo run -p example-tracing-aka-logging //! ``` use axum::{ diff --git a/examples/unix-domain-socket/src/main.rs b/examples/unix-domain-socket/src/main.rs index f23734e9..2f67a4c1 100644 --- a/examples/unix-domain-socket/src/main.rs +++ b/examples/unix-domain-socket/src/main.rs @@ -1,7 +1,7 @@ //! Run with //! //! ```not_rust -//! cargo run -p example-unix-domain-socket +//! cd examples && cargo run -p example-unix-domain-socket //! ``` #[cfg(unix)] diff --git a/examples/validator/src/main.rs b/examples/validator/src/main.rs index ed0d3463..c8ce8c08 100644 --- a/examples/validator/src/main.rs +++ b/examples/validator/src/main.rs @@ -1,7 +1,7 @@ //! Run with //! //! ```not_rust -//! cargo run -p example-validator +//! cd examples && cargo run -p example-validator //! //! curl '127.0.0.1:3000?name=' //! -> Input validation error: [name: Can not be empty] diff --git a/examples/versioning/src/main.rs b/examples/versioning/src/main.rs index 2cde3edb..48ade3c9 100644 --- a/examples/versioning/src/main.rs +++ b/examples/versioning/src/main.rs @@ -1,7 +1,7 @@ //! Run with //! //! ```not_rust -//! cargo run -p example-versioning +//! cd examples && cargo run -p example-versioning //! ``` use axum::{ diff --git a/examples/websockets/src/main.rs b/examples/websockets/src/main.rs index f38da380..9dab67a0 100644 --- a/examples/websockets/src/main.rs +++ b/examples/websockets/src/main.rs @@ -3,7 +3,7 @@ //! Run with //! //! ```not_rust -//! cargo run -p example-websockets +//! cd examples && cargo run -p example-websockets //! ``` use axum::{