Skip to content

Commit 0499a49

Browse files
Evalironbjergprestwich
authored
feat(ci): feature checks (#25)
* feat(ci): feature checks Adds feature checks to CI. Closes ENG-835 * chore: rename action * beep boop * fix: feature gate `Router::into_axum_with_handle` (#24) * fix: clippy --------- Co-authored-by: onbjerg <[email protected]> Co-authored-by: James <[email protected]>
1 parent c43875d commit 0499a49

File tree

9 files changed

+20
-16
lines changed

9 files changed

+20
-16
lines changed

.github/workflows/rust-ci.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
name: Rust CI
2-
32
on:
3+
workflow_dispatch:
44
push:
55
branches: [main]
66
pull_request:
7+
env:
8+
CARGO_TERM_COLOR: always
79

8-
# simplest example of using the rust-base action
910
jobs:
10-
rust-base:
11-
uses: init4tech/actions/.github/workflows/rust-base.yml@main
11+
rust-library-base:
12+
uses: init4tech/actions/.github/workflows/rust-library-base.yml@main

Cargo.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,34 @@ serde = { version = "1.0.217", features = ["derive"] }
2020
serde_json = { version = "1.0.135", features = ["raw_value"] }
2121
thiserror = "2.0.9"
2222
tokio = { version = "1.43.0", features = ["sync", "rt", "macros"] }
23+
tokio-util = { version = "0.7.13", features = ["io", "rt"] }
2324
tower = { version = "0.5.2", features = ["util"] }
2425
tracing = "0.1.41"
2526

2627
# axum
2728
axum = { version = "0.8.1", optional = true }
29+
mime = { version = "0.3.17", optional = true}
2830

2931
# pubsub
3032
tokio-stream = { version = "0.1.17", optional = true }
3133

3234
# ipc
3335
interprocess = { version = "2.2.2", features = ["async", "tokio"], optional = true }
34-
tokio-util = { version = "0.7.13", optional = true, features = ["io", "rt"] }
3536

3637
# ws
3738
tokio-tungstenite = { version = "0.26.1", features = ["rustls-tls-webpki-roots"], optional = true }
3839
futures-util = { version = "0.3.31", optional = true }
39-
mime = "0.3.17"
4040

4141
[dev-dependencies]
4242
tempfile = "3.15.0"
4343
tracing-subscriber = "0.3.19"
4444

4545
[features]
4646
default = ["axum", "ws", "ipc"]
47-
axum = ["dep:axum"]
47+
axum = ["dep:axum", "dep:mime"]
4848
pubsub = ["dep:tokio-stream"]
49-
ipc = ["pubsub", "dep:tokio-util", "dep:interprocess"]
49+
ipc = ["pubsub", "dep:interprocess"]
5050
ws = ["pubsub", "dep:tokio-tungstenite", "dep:futures-util"]
51-
tokio-util = ["dep:tokio-util"]
5251

5352
[profile.release]
5453
opt-level = 3

src/router.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,10 @@ where
346346
///
347347
/// This method allows users to specify a runtime handle for the router to
348348
/// use. This runtime is accessible to all handlers invoked by the router.
349-
/// Handlers.
350349
///
351350
/// Tasks spawned by the router will be spawned on the provided runtime,
352351
/// and automatically cancelled when the returned `axum::Router` is dropped.
352+
#[cfg(feature = "axum")]
353353
pub fn into_axum_with_handle(
354354
self,
355355
path: &str,

src/routes/ctx.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
use std::future::Future;
2-
31
use crate::{types::Request, RpcSend, TaskSet};
42
use serde_json::value::RawValue;
3+
use std::future::Future;
54
use tokio::{runtime::Handle, sync::mpsc, task::JoinHandle};
65
use tokio_util::sync::WaitForCancellationFutureOwned;
76
use tracing::error;
@@ -54,6 +53,7 @@ impl From<Handle> for HandlerCtx {
5453

5554
impl HandlerCtx {
5655
/// Create a new handler context.
56+
#[allow(dead_code)] // used in pubsub and axum features
5757
pub(crate) const fn new(
5858
notifications: Option<mpsc::Sender<Box<RawValue>>>,
5959
tasks: TaskSet,

src/routes/handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ pub struct PhantomParams<T>(PhantomData<T>);
120120
///
121121
/// 1. The handler takes EITHER `params` or `state`.
122122
/// 2. The `S` type of the router would also be a valid `Params` type (i.e. it
123-
/// impls [`DeserializeOwned`] and satisfies the other
124-
/// requirements of [`RpcRecv`]).
123+
/// impls [`DeserializeOwned`] and satisfies the other
124+
/// requirements of [`RpcRecv`]).
125125
/// 3. The argument to the handler matches the `S` type of the router.
126126
///
127127
/// ```compile_fail

src/tasks.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ impl From<Handle> for TaskSet {
2424
}
2525
}
2626

27+
#[allow(dead_code)] // used in pubsub and axum features
2728
impl TaskSet {
2829
/// Create a new [`TaskSet`] with a handle.
2930
pub(crate) fn with_handle(handle: Handle) -> Self {

tests/common/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
use std::time::Duration;
2-
31
use ajj::{HandlerCtx, Router};
42
use serde_json::{json, Value};
3+
use std::time::Duration;
54
use tokio::time::{self, timeout};
65

76
/// Instantiate a router for testing.

tests/ipc.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg(feature = "ipc")]
2+
13
mod common;
24
use common::{test_router, TestClient};
35

tests/ws.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg(feature = "ws")]
2+
13
mod common;
24
use common::{test_router, TestClient};
35

0 commit comments

Comments
 (0)