Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .github/workflows/rust-ci.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
name: Rust CI

on:
workflow_dispatch:
push:
branches: [main]
pull_request:
env:
CARGO_TERM_COLOR: always

# simplest example of using the rust-base action
jobs:
rust-base:
uses: init4tech/actions/.github/workflows/rust-base.yml@main
rust-library-base:
uses: init4tech/actions/.github/workflows/rust-library-base.yml@main
9 changes: 4 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,34 @@ serde = { version = "1.0.217", features = ["derive"] }
serde_json = { version = "1.0.135", features = ["raw_value"] }
thiserror = "2.0.9"
tokio = { version = "1.43.0", features = ["sync", "rt", "macros"] }
tokio-util = { version = "0.7.13", features = ["io", "rt"] }
tower = { version = "0.5.2", features = ["util"] }
tracing = "0.1.41"

# axum
axum = { version = "0.8.1", optional = true }
mime = { version = "0.3.17", optional = true}

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

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

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

[dev-dependencies]
tempfile = "3.15.0"
tracing-subscriber = "0.3.19"

[features]
default = ["axum", "ws", "ipc"]
axum = ["dep:axum"]
axum = ["dep:axum", "dep:mime"]
pubsub = ["dep:tokio-stream"]
ipc = ["pubsub", "dep:tokio-util", "dep:interprocess"]
ipc = ["pubsub", "dep:interprocess"]
ws = ["pubsub", "dep:tokio-tungstenite", "dep:futures-util"]
tokio-util = ["dep:tokio-util"]

[profile.release]
opt-level = 3
Expand Down
2 changes: 1 addition & 1 deletion src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,10 @@ where
///
/// This method allows users to specify a runtime handle for the router to
/// use. This runtime is accessible to all handlers invoked by the router.
/// Handlers.
///
/// Tasks spawned by the router will be spawned on the provided runtime,
/// and automatically cancelled when the returned `axum::Router` is dropped.
#[cfg(feature = "axum")]
pub fn into_axum_with_handle(
self,
path: &str,
Expand Down
4 changes: 2 additions & 2 deletions src/routes/ctx.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::future::Future;

use crate::{types::Request, RpcSend, TaskSet};
use serde_json::value::RawValue;
use std::future::Future;
use tokio::{runtime::Handle, sync::mpsc, task::JoinHandle};
use tokio_util::sync::WaitForCancellationFutureOwned;
use tracing::error;
Expand Down Expand Up @@ -54,6 +53,7 @@ impl From<Handle> for HandlerCtx {

impl HandlerCtx {
/// Create a new handler context.
#[allow(dead_code)] // used in pubsub and axum features
pub(crate) const fn new(
notifications: Option<mpsc::Sender<Box<RawValue>>>,
tasks: TaskSet,
Expand Down
4 changes: 2 additions & 2 deletions src/routes/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ pub struct PhantomParams<T>(PhantomData<T>);
///
/// 1. The handler takes EITHER `params` or `state`.
/// 2. The `S` type of the router would also be a valid `Params` type (i.e. it
/// impls [`DeserializeOwned`] and satisfies the other
/// requirements of [`RpcRecv`]).
/// impls [`DeserializeOwned`] and satisfies the other
/// requirements of [`RpcRecv`]).
/// 3. The argument to the handler matches the `S` type of the router.
///
/// ```compile_fail
Expand Down
1 change: 1 addition & 0 deletions src/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ impl From<Handle> for TaskSet {
}
}

#[allow(dead_code)] // used in pubsub and axum features
impl TaskSet {
/// Create a new [`TaskSet`] with a handle.
pub(crate) fn with_handle(handle: Handle) -> Self {
Expand Down
3 changes: 1 addition & 2 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::time::Duration;

use ajj::{HandlerCtx, Router};
use serde_json::{json, Value};
use std::time::Duration;
use tokio::time::{self, timeout};

/// Instantiate a router for testing.
Expand Down
2 changes: 2 additions & 0 deletions tests/ipc.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(feature = "ipc")]

mod common;
use common::{test_router, TestClient};

Expand Down
2 changes: 2 additions & 0 deletions tests/ws.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(feature = "ws")]

mod common;
use common::{test_router, TestClient};

Expand Down