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

support axum 0.7 and upgraded http and hyper dependencies #33

Closed
wants to merge 4 commits into from
Closed
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
15 changes: 8 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ runtime-tokio-rustls = ["sqlx/runtime-tokio-rustls"]
features = ["all-databases", "runtime-tokio-rustls"]

[dependencies]
axum-core = "0.3"
axum-core = "0.4"
bytes = "1"
futures-core = "0.3"
http = "0.2"
http-body = "0.4"
http = "1"
http-body = "1"
http-body-util = "0.1.0"
parking_lot = "0.12"
sqlx = { version = "0.7", default-features = false }
thiserror = "1"
Expand All @@ -39,7 +40,7 @@ tower-service = "0.3"

[dev-dependencies]
axum-sqlx-tx = { path = ".", features = ["runtime-tokio-rustls", "sqlite"] }
axum = "0.6.4"
hyper = "0.14.17"
tokio = { version = "1.17.0", features = ["macros", "rt-multi-thread"] }
tower = "0.4.12"
axum = "0.7"
hyper = "1"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
tower = "0.4"
9 changes: 7 additions & 2 deletions examples/example.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! A silly server that generates random numers, but only commits positive ones.

use std::error::Error;
use std::net::SocketAddr;

use axum::{response::IntoResponse, routing::get, Json};
use http::StatusCode;
Expand Down Expand Up @@ -28,9 +29,13 @@ async fn main() -> Result<(), Box<dyn Error>> {
// Add the Tx state
.with_state(state);

let server = axum::Server::bind(&([0, 0, 0, 0], 0).into()).serve(app.into_make_service());
let addr: SocketAddr = ([0, 0, 0, 0], 0).into();
let server = axum::serve(
tokio::net::TcpListener::bind(&addr).await.unwrap(),
app.into_make_service(),
);

println!("Listening on {}", server.local_addr());
println!("Listening on {}", addr);
server.await?;

Ok(())
Expand Down
9 changes: 7 additions & 2 deletions src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
use axum_core::response::IntoResponse;
use bytes::Bytes;
use futures_core::future::BoxFuture;
use http_body::{combinators::UnsyncBoxBody, Body};
use http_body::Body;
use http_body_util::combinators::UnsyncBoxBody;
use http_body_util::BodyExt;

use crate::{tx::TxSlot, Marker, State};

Expand Down Expand Up @@ -118,7 +120,10 @@

if !res.status().is_server_error() && !res.status().is_client_error() {
if let Err(error) = transaction.commit().await {
return Ok(error.into().into_response());
return Ok(error
.into()
.into_response()
.map(|body| body.map_err(axum_core::Error::new).boxed_unsync()));
}
}

Expand All @@ -145,6 +150,6 @@
.route("/", axum::routing::get(|| async { "hello" }))
.layer(layer);

axum::Server::bind(todo!()).serve(app.into_make_service());

Check failure on line 153 in src/layer.rs

View workflow job for this annotation

GitHub Actions / test

failed to resolve: could not find `Server` in `axum`
}
}
13 changes: 10 additions & 3 deletions src/slot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,15 @@ impl<T> Slot<T> {
}
}

impl<T> Clone for Slot<T> {
fn clone(&self) -> Self {
Self(self.0.clone())
}
}


/// A lease of a value from a `Slot`.
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct Lease<T>(lease::State<T>);

impl<T> Lease<T> {
Expand Down Expand Up @@ -110,10 +117,10 @@ mod lease {

use parking_lot::Mutex;

#[derive(Debug)]
#[derive(Debug, Clone)]
pub(super) struct State<T>(Inner<T>);

#[derive(Debug)]
#[derive(Debug, Clone)]
enum Inner<T> {
Dropped,
Stolen,
Expand Down
9 changes: 9 additions & 0 deletions src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,15 @@ impl<DB: Marker> Lazy<DB> {
}
}

impl<DB: Marker> Clone for Lazy<DB> {
fn clone(&self) -> Self {
Self {
state: self.state.clone(),
tx: self.tx.clone(),
}
}
}

impl<'c, DB, E> sqlx::Executor<'c> for &'c mut Tx<DB, E>
where
DB: Marker,
Expand Down
Loading