mirror of https://github.com/rwf2/Rocket.git
Replace uses of `FnBox`; `Box<dyn FnOnce>` now implements `FnOnce`.
This commit is contained in:
parent
f1f09f17ca
commit
8574dbf841
|
@ -8,8 +8,8 @@ use yansi::Color::{Red, Yellow, Blue};
|
||||||
use version_check::{supports_features, is_min_version, is_min_date};
|
use version_check::{supports_features, is_min_version, is_min_date};
|
||||||
|
|
||||||
// Specifies the minimum nightly version needed to compile Rocket.
|
// Specifies the minimum nightly version needed to compile Rocket.
|
||||||
const MIN_DATE: &'static str = "2018-10-05";
|
const MIN_DATE: &'static str = "2019-04-05";
|
||||||
const MIN_VERSION: &'static str = "1.31.0-nightly";
|
const MIN_VERSION: &'static str = "1.35.0-nightly";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let ok_channel = supports_features();
|
let ok_channel = supports_features();
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use std::boxed::FnBox;
|
|
||||||
|
|
||||||
use {Rocket, Request, Response, Data};
|
use {Rocket, Request, Response, Data};
|
||||||
use fairing::{Fairing, Kind, Info};
|
use fairing::{Fairing, Kind, Info};
|
||||||
|
@ -43,14 +42,14 @@ pub struct AdHoc {
|
||||||
|
|
||||||
enum AdHocKind {
|
enum AdHocKind {
|
||||||
/// An ad-hoc **attach** fairing. Called when the fairing is attached.
|
/// An ad-hoc **attach** fairing. Called when the fairing is attached.
|
||||||
Attach(Mutex<Option<Box<FnBox(Rocket) -> Result<Rocket, Rocket> + Send + 'static>>>),
|
Attach(Mutex<Option<Box<dyn FnOnce(Rocket) -> Result<Rocket, Rocket> + Send + 'static>>>),
|
||||||
/// An ad-hoc **launch** fairing. Called just before Rocket launches.
|
/// An ad-hoc **launch** fairing. Called just before Rocket launches.
|
||||||
Launch(Mutex<Option<Box<FnBox(&Rocket) + Send + 'static>>>),
|
Launch(Mutex<Option<Box<dyn FnOnce(&Rocket) + Send + 'static>>>),
|
||||||
/// An ad-hoc **request** fairing. Called when a request is received.
|
/// An ad-hoc **request** fairing. Called when a request is received.
|
||||||
Request(Box<Fn(&mut Request, &Data) + Send + Sync + 'static>),
|
Request(Box<dyn Fn(&mut Request, &Data) + Send + Sync + 'static>),
|
||||||
/// An ad-hoc **response** fairing. Called when a response is ready to be
|
/// An ad-hoc **response** fairing. Called when a response is ready to be
|
||||||
/// sent to a client.
|
/// sent to a client.
|
||||||
Response(Box<Fn(&Request, &mut Response) + Send + Sync + 'static>),
|
Response(Box<dyn Fn(&Request, &mut Response) + Send + Sync + 'static>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AdHoc {
|
impl AdHoc {
|
||||||
|
@ -146,9 +145,10 @@ impl Fairing for AdHoc {
|
||||||
fn on_attach(&self, rocket: Rocket) -> Result<Rocket, Rocket> {
|
fn on_attach(&self, rocket: Rocket) -> Result<Rocket, Rocket> {
|
||||||
if let AdHocKind::Attach(ref mutex) = self.kind {
|
if let AdHocKind::Attach(ref mutex) = self.kind {
|
||||||
let mut option = mutex.lock().expect("AdHoc::Attach lock");
|
let mut option = mutex.lock().expect("AdHoc::Attach lock");
|
||||||
option.take()
|
let f = option
|
||||||
.expect("internal error: `on_attach` single-call invariant broken")
|
.take()
|
||||||
.call_box((rocket,))
|
.expect("internal error: `on_attach` single-call invariant broken");
|
||||||
|
f(rocket)
|
||||||
} else {
|
} else {
|
||||||
Ok(rocket)
|
Ok(rocket)
|
||||||
}
|
}
|
||||||
|
@ -157,9 +157,10 @@ impl Fairing for AdHoc {
|
||||||
fn on_launch(&self, rocket: &Rocket) {
|
fn on_launch(&self, rocket: &Rocket) {
|
||||||
if let AdHocKind::Launch(ref mutex) = self.kind {
|
if let AdHocKind::Launch(ref mutex) = self.kind {
|
||||||
let mut option = mutex.lock().expect("AdHoc::Launch lock");
|
let mut option = mutex.lock().expect("AdHoc::Launch lock");
|
||||||
option.take()
|
let f = option
|
||||||
.expect("internal error: `on_launch` single-call invariant broken")
|
.take()
|
||||||
.call_box((rocket, ))
|
.expect("internal error: `on_launch` single-call invariant broken");
|
||||||
|
f(rocket)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#![feature(specialization)]
|
#![feature(specialization)]
|
||||||
#![feature(decl_macro)]
|
#![feature(decl_macro)]
|
||||||
#![feature(try_trait)]
|
#![feature(try_trait)]
|
||||||
#![feature(fnbox)]
|
|
||||||
#![feature(never_type)]
|
#![feature(never_type)]
|
||||||
#![feature(proc_macro_hygiene)]
|
#![feature(proc_macro_hygiene)]
|
||||||
#![feature(crate_visibility_modifier)]
|
#![feature(crate_visibility_modifier)]
|
||||||
|
|
Loading…
Reference in New Issue