mirror of
https://github.com/tokio-rs/axum.git
synced 2026-09-03 00:00:07 +02:00
Add Send + Sync check to all services (#277)
Should prevent us accidentally introducing breaking changes. Fixes https://github.com/tokio-rs/axum/issues/275
This commit is contained in:
@@ -29,6 +29,13 @@ pub struct IntoMakeServiceWithConnectInfo<S, C> {
|
|||||||
_connect_info: PhantomData<fn() -> C>,
|
_connect_info: PhantomData<fn() -> C>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn traits() {
|
||||||
|
use crate::tests::*;
|
||||||
|
assert_send::<IntoMakeServiceWithConnectInfo<(), NotSendSync>>();
|
||||||
|
assert_sync::<IntoMakeServiceWithConnectInfo<(), NotSendSync>>();
|
||||||
|
}
|
||||||
|
|
||||||
impl<S, C> IntoMakeServiceWithConnectInfo<S, C> {
|
impl<S, C> IntoMakeServiceWithConnectInfo<S, C> {
|
||||||
pub(crate) fn new(svc: S) -> Self {
|
pub(crate) fn new(svc: S) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|||||||
@@ -132,6 +132,13 @@ pub struct ExtractorMiddleware<S, E> {
|
|||||||
_extractor: PhantomData<fn() -> E>,
|
_extractor: PhantomData<fn() -> E>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn traits() {
|
||||||
|
use crate::tests::*;
|
||||||
|
assert_send::<ExtractorMiddleware<(), NotSendSync>>();
|
||||||
|
assert_sync::<ExtractorMiddleware<(), NotSendSync>>();
|
||||||
|
}
|
||||||
|
|
||||||
impl<S, E> Clone for ExtractorMiddleware<S, E>
|
impl<S, E> Clone for ExtractorMiddleware<S, E>
|
||||||
where
|
where
|
||||||
S: Clone,
|
S: Clone,
|
||||||
|
|||||||
@@ -17,6 +17,13 @@ pub struct IntoService<H, B, T> {
|
|||||||
_marker: PhantomData<fn() -> (B, T)>,
|
_marker: PhantomData<fn() -> (B, T)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn traits() {
|
||||||
|
use crate::tests::*;
|
||||||
|
assert_send::<IntoService<(), NotSendSync, NotSendSync>>();
|
||||||
|
assert_sync::<IntoService<(), NotSendSync, NotSendSync>>();
|
||||||
|
}
|
||||||
|
|
||||||
impl<H, B, T> IntoService<H, B, T> {
|
impl<H, B, T> IntoService<H, B, T> {
|
||||||
pub(super) fn new(handler: H) -> Self {
|
pub(super) fn new(handler: H) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|||||||
@@ -441,6 +441,13 @@ pub struct OnMethod<H, B, T, F> {
|
|||||||
pub(crate) _marker: PhantomData<fn() -> (B, T)>,
|
pub(crate) _marker: PhantomData<fn() -> (B, T)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn traits() {
|
||||||
|
use crate::tests::*;
|
||||||
|
assert_send::<OnMethod<(), NotSendSync, NotSendSync, ()>>();
|
||||||
|
assert_sync::<OnMethod<(), NotSendSync, NotSendSync, ()>>();
|
||||||
|
}
|
||||||
|
|
||||||
impl<H, B, T, F> fmt::Debug for OnMethod<H, B, T, F>
|
impl<H, B, T, F> fmt::Debug for OnMethod<H, B, T, F>
|
||||||
where
|
where
|
||||||
T: fmt::Debug,
|
T: fmt::Debug,
|
||||||
|
|||||||
@@ -1106,4 +1106,33 @@ mod tests {
|
|||||||
route_spec
|
route_spec
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn traits() {
|
||||||
|
use crate::tests::*;
|
||||||
|
|
||||||
|
assert_send::<Router<()>>();
|
||||||
|
assert_sync::<Router<()>>();
|
||||||
|
|
||||||
|
assert_send::<Route<(), ()>>();
|
||||||
|
assert_sync::<Route<(), ()>>();
|
||||||
|
|
||||||
|
assert_send::<EmptyRouter<NotSendSync>>();
|
||||||
|
assert_sync::<EmptyRouter<NotSendSync>>();
|
||||||
|
|
||||||
|
assert_send::<BoxRoute<(), ()>>();
|
||||||
|
assert_sync::<BoxRoute<(), ()>>();
|
||||||
|
|
||||||
|
assert_send::<Layered<()>>();
|
||||||
|
assert_sync::<Layered<()>>();
|
||||||
|
|
||||||
|
assert_send::<Nested<(), ()>>();
|
||||||
|
assert_sync::<Nested<(), ()>>();
|
||||||
|
|
||||||
|
assert_send::<CheckInfallible<()>>();
|
||||||
|
assert_sync::<CheckInfallible<()>>();
|
||||||
|
|
||||||
|
assert_send::<IntoMakeService<()>>();
|
||||||
|
assert_sync::<IntoMakeService<()>>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,13 @@ pub struct Or<A, B> {
|
|||||||
pub(super) second: B,
|
pub(super) second: B,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn traits() {
|
||||||
|
use crate::tests::*;
|
||||||
|
assert_send::<Or<(), ()>>();
|
||||||
|
assert_sync::<Or<(), ()>>();
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(warnings)]
|
#[allow(warnings)]
|
||||||
impl<A, B, ReqBody> Service<Request<ReqBody>> for Or<A, B>
|
impl<A, B, ReqBody> Service<Request<ReqBody>> for Or<A, B>
|
||||||
where
|
where
|
||||||
|
|||||||
@@ -596,3 +596,14 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn traits() {
|
||||||
|
use crate::tests::*;
|
||||||
|
|
||||||
|
assert_send::<OnMethod<(), (), NotSendSync>>();
|
||||||
|
assert_sync::<OnMethod<(), (), NotSendSync>>();
|
||||||
|
|
||||||
|
assert_send::<HandleError<(), (), NotSendSync>>();
|
||||||
|
assert_sync::<HandleError<(), (), NotSendSync>>();
|
||||||
|
}
|
||||||
|
|||||||
@@ -721,3 +721,5 @@ where
|
|||||||
pub(crate) fn assert_send<T: Send>() {}
|
pub(crate) fn assert_send<T: Send>() {}
|
||||||
pub(crate) fn assert_sync<T: Sync>() {}
|
pub(crate) fn assert_sync<T: Sync>() {}
|
||||||
pub(crate) fn assert_unpin<T: Unpin>() {}
|
pub(crate) fn assert_unpin<T: Unpin>() {}
|
||||||
|
|
||||||
|
pub(crate) struct NotSendSync(*const ());
|
||||||
|
|||||||
Reference in New Issue
Block a user