1
0
Fork 0
mirror of https://github.com/tokio-rs/axum.git synced 2025-02-19 11:39:53 +01:00

Add Send + Sync check to all services ()

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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 77 additions and 0 deletions

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 {

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,

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 {

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,

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<()>>();
}
}

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

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>>();
}

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 ());