use FnOnce instead of Fn

This commit is contained in:
fakeshadow 2020-12-23 03:18:58 +08:00
parent 6012bcf941
commit 54e8b6628c
2 changed files with 3 additions and 6 deletions

View File

@ -299,7 +299,7 @@ impl ServerBuilder {
pub fn on_stop<F, Fut>(mut self, future: F) -> Self
where
F: Fn() -> Fut + 'static,
F: FnOnce() -> Fut + 'static,
Fut: Future<Output = ()>,
{
self.on_stop = Box::pin(async move { future().await });

View File

@ -201,11 +201,8 @@ fn test_on_stop() {
let srv: Server = Server::build()
.backlog(100)
.disable_signals()
.on_stop(move || {
let bool = bool.clone();
async move {
bool.store(true, Ordering::SeqCst);
}
.on_stop(|| async move {
bool.store(true, Ordering::SeqCst);
})
.bind("test", addr, move || {
fn_service(|io: TcpStream| async move {