Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update axum to 0.8 #23

Merged
merged 2 commits into from
Jan 24, 2025
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [0.2.0] - 2025-01-24

### Changed
- axum upgraded from 0.7 to 0.8
- feature `axum-07` as been removed in favor of feature `axum-08`

## [0.1.0] - 2024-12-26

### Added
Expand Down
65 changes: 58 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 13 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
[workspace]
members = ["build", "client", "error", "server", "integration", "example/server", "example/client"]
members = [
"build",
"client",
"error",
"server",
"integration",
"example/server",
"example/client",
]
resolver = "2"

[workspace.package]
Expand All @@ -9,8 +17,8 @@ license = "Apache-2.0"
rust-version = "1.79"

[workspace.dependencies]
axum = { version = "0.7.9", default-features = false }
axum-core-04 = { package = "axum-core", version = "0.4.5" }
axum = { version = "0.8", default-features = false }
axum-core-05 = { package = "axum-core", version = "0.5.0" }
eyre = "0.6.10"
http = "1"
http-body = "1"
Expand All @@ -31,8 +39,8 @@ tonic = { version = "0.12.3", default-features = false }
tonic-012 = { package = "tonic", version = "0.12.3", default-features = false }
tonic-build = "0.12.3"
tower-service = "0.3.3"
tower = "0.5.1"
tower = "0.5.2"
tower-http = "0.6.2"
tracing = "0.1.35"
trait-variant = "0.1.2"
twurst-error = { path = "error", version = "0.1.0" }
twurst-error = { path = "error", version = "0.2.0" }
2 changes: 1 addition & 1 deletion build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "twurst-build"
description = "Build script to generate bindings for .proto files for Twirp"
repository = "https://github.com/helsing-ai/twurst"
documentation = "https://docs.rs/twurst-build"
version = "0.1.0"
version = "0.2.0"
authors.workspace = true
edition.workspace = true
license.workspace = true
Expand Down
8 changes: 4 additions & 4 deletions build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,10 @@ impl TwirpServiceGenerator {
write!(buf, "| {{")?;
writeln!(buf, " async move {{")?;
write!(buf, " service.{}(request", method.name)?;
for _ in 0..self.request_extractors.len() {
for (_name, type_name) in &self.request_extractors {
write!(
buf,
", match ::twurst_server::codegen::FromRequestParts::from_request_parts(&mut parts, &state).await {{ Ok(r) => r, Err(e) => {{ return Err(::twurst_server::codegen::twirp_error_from_response(e).await) }} }}"
", match <{type_name} as ::twurst_server::codegen::FromRequestParts<_>>::from_request_parts(&mut parts, &state).await {{ Ok(r) => r, Err(e) => {{ return Err(::twurst_server::codegen::twirp_error_from_response(e).await) }} }}"
)?;
}
writeln!(buf, ").await")?;
Expand Down Expand Up @@ -407,10 +407,10 @@ impl TwirpServiceGenerator {
write!(buf, "Ok(Box::into_pin(")?;
}
write!(buf, "service.{}(request", method.name)?;
for _ in 0..self.request_extractors.len() {
for (_name, type_name) in &self.request_extractors {
write!(
buf,
", match ::twurst_server::codegen::FromRequestParts::from_request_parts(&mut parts, &()).await {{ Ok(r) => r, Err(e) => {{ return Err(::twurst_server::codegen::twirp_error_from_response(e).await) }} }}"
", match <{type_name} as ::twurst_server::codegen::FromRequestParts<_>>::from_request_parts(&mut parts, &()).await {{ Ok(r) => r, Err(e) => {{ return Err(::twurst_server::codegen::twirp_error_from_response(e).await) }} }}"
)?;
}
write!(buf, ").await")?;
Expand Down
2 changes: 1 addition & 1 deletion client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description = "Twirp client related code"
keywords = ["Twirp"]
repository = "https://github.com/helsing-ai/twurst"
documentation = "https://docs.rs/twurst-client"
version = "0.1.0"
version = "0.2.0"
authors.workspace = true
edition.workspace = true
license.workspace = true
Expand Down
6 changes: 3 additions & 3 deletions error/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ name = "twurst-error"
description = "Twirp error struct"
repository = "https://github.com/helsing-ai/twurst"
documentation = "https://docs.rs/twurst-error"
version = "0.1.0"
version = "0.2.0"
authors.workspace = true
edition.workspace = true
license.workspace = true
rust-version.workspace = true

[features]
axum-07 = ["dep:axum-core-04", "http"]
axum-08 = ["dep:axum-core-05", "http"]
http = ["dep:http", "dep:serde_json", "serde"]
serde = ["dep:serde"]
tonic-012 = ["dep:tonic-012"]

[dependencies]
axum-core-04 = { workspace = true, optional = true }
axum-core-05 = { workspace = true, optional = true }
http = { workspace = true, optional = true }
serde = { workspace = true, features = ["derive"], optional = true }
serde_json = { workspace = true, optional = true }
Expand Down
6 changes: 3 additions & 3 deletions error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,10 @@ impl<B: AsRef<[u8]>> From<http::Response<B>> for TwirpError {
}
}

#[cfg(feature = "axum-07")]
impl axum_core_04::response::IntoResponse for TwirpError {
#[cfg(feature = "axum-08")]
impl axum_core_05::response::IntoResponse for TwirpError {
#[inline]
fn into_response(self) -> axum_core_04::response::Response {
fn into_response(self) -> axum_core_05::response::Response {
self.into()
}
}
Expand Down
3 changes: 1 addition & 2 deletions integration/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::proto::{test_request, test_response, IntegrationService, TestRequest,
use axum::extract::FromRequestParts;
use axum::http::header::AUTHORIZATION;
use axum::http::request::Parts;
use axum::{async_trait, Router};
use axum::Router;
use eyre::Result;
use std::net::{Ipv4Addr, SocketAddrV4};
use std::pin::pin;
Expand Down Expand Up @@ -135,7 +135,6 @@ pub async fn serve_grpc() -> Result<Server> {

pub struct ExtractBearerToken(pub String);

#[async_trait]
impl<S> FromRequestParts<S> for ExtractBearerToken
where
S: Send + Sync,
Expand Down
11 changes: 8 additions & 3 deletions server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@ description = "Twirp server related code"
keywords = ["Twirp"]
repository = "https://github.com/helsing-ai/twurst"
documentation = "https://docs.rs/twurst-server"
version = "0.1.0"
version = "0.2.0"
authors.workspace = true
edition.workspace = true
license.workspace = true
rust-version.workspace = true

[features]
grpc = ["dep:tonic", "dep:tokio-stream", "dep:pin-project-lite", "twurst-error/tonic-012"]
grpc = [
"dep:tonic",
"dep:tokio-stream",
"dep:pin-project-lite",
"twurst-error/tonic-012",
]

[dependencies]
twurst-error = { workspace = true, features = ["axum-07"] }
twurst-error = { workspace = true, features = ["axum-08"] }
axum.workspace = true
http-body-util.workspace = true
pin-project-lite = { workspace = true, optional = true }
Expand Down
10 changes: 5 additions & 5 deletions server/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl<S: Clone + Send + Sync + 'static, RS: Clone + Send + Sync + 'static> TwirpR
>(
mut self,
path: &str,
call: impl (Fn(S, I, RequestParts, RS) -> F) + Clone + Send + 'static,
call: impl (Fn(S, I, RequestParts, RS) -> F) + Clone + Send + Sync + 'static,
) -> Self {
let service = self.service.clone();
self.router = self.router.route(
Expand Down Expand Up @@ -215,7 +215,7 @@ impl<S: Clone + Send + Sync + 'static> GrpcRouter<S> {
pub fn route<
I: ReflectMessage + Default + 'static,
O: ReflectMessage + 'static,
C: (Fn(S, I, RequestParts) -> F) + Clone + Send + 'static,
C: (Fn(S, I, RequestParts) -> F) + Clone + Send + Sync + 'static,
F: Future<Output = Result<O, TwirpError>> + Send + 'static,
>(
mut self,
Expand All @@ -238,7 +238,7 @@ impl<S: Clone + Send + Sync + 'static> GrpcRouter<S> {
pub fn route_server_streaming<
I: ReflectMessage + Default + 'static,
O: ReflectMessage + 'static,
C: (Fn(S, I, RequestParts) -> F) + Clone + Send + 'static,
C: (Fn(S, I, RequestParts) -> F) + Clone + Send + Sync + 'static,
F: Future<Output = Result<OS, TwirpError>> + Send + 'static,
OS: Stream<Item = Result<O, TwirpError>> + Send + 'static,
>(
Expand All @@ -262,7 +262,7 @@ impl<S: Clone + Send + Sync + 'static> GrpcRouter<S> {
pub fn route_client_streaming<
I: ReflectMessage + Default + 'static,
O: ReflectMessage + 'static,
C: (Fn(S, GrpcClientStream<I>, RequestParts) -> F) + Clone + Send + 'static,
C: (Fn(S, GrpcClientStream<I>, RequestParts) -> F) + Clone + Send + Sync + 'static,
F: Future<Output = Result<O, TwirpError>> + Send + 'static,
>(
mut self,
Expand All @@ -285,7 +285,7 @@ impl<S: Clone + Send + Sync + 'static> GrpcRouter<S> {
pub fn route_streaming<
I: ReflectMessage + Default + 'static,
O: ReflectMessage + 'static,
C: (Fn(S, GrpcClientStream<I>, RequestParts) -> F) + Clone + Send + 'static,
C: (Fn(S, GrpcClientStream<I>, RequestParts) -> F) + Clone + Send + Sync + 'static,
F: Future<Output = Result<OS, TwirpError>> + Send + 'static,
OS: Stream<Item = Result<O, TwirpError>> + Send + 'static,
>(
Expand Down
Loading