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:
David Pedersen
2021-08-26 20:59:55 +02:00
committed by GitHub
parent e6ca9e4b04
commit 4c5068c01f
8 changed files with 77 additions and 0 deletions
+7
View File
@@ -29,6 +29,13 @@ pub struct IntoMakeServiceWithConnectInfo<S, 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> {
pub(crate) fn new(svc: S) -> Self {
Self {
+7
View File
@@ -132,6 +132,13 @@ pub struct ExtractorMiddleware<S, 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>
where
S: Clone,
+7
View File
@@ -17,6 +17,13 @@ pub struct IntoService<H, 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> {
pub(super) fn new(handler: H) -> Self {
Self {
+7
View File
@@ -441,6 +441,13 @@ pub struct OnMethod<H, B, T, F> {
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>
where
T: fmt::Debug,
+29
View File
@@ -1106,4 +1106,33 @@ mod tests {
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<()>>();
}
}
+7
View File
@@ -24,6 +24,13 @@ pub struct Or<A, B> {
pub(super) second: B,
}
#[test]
fn traits() {
use crate::tests::*;
assert_send::<Or<(), ()>>();
assert_sync::<Or<(), ()>>();
}
#[allow(warnings)]
impl<A, B, ReqBody> Service<Request<ReqBody>> for Or<A, B>
where
+11
View File
@@ -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>>();
}
+2
View File
@@ -721,3 +721,5 @@ where
pub(crate) fn assert_send<T: Send>() {}
pub(crate) fn assert_sync<T: Sync>() {}
pub(crate) fn assert_unpin<T: Unpin>() {}
pub(crate) struct NotSendSync(*const ());