1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
//! A filter that matches any route. use futures::{Future, Poll}; use ::never::Never; use ::filter::{FilterBase, Filter}; /// A filter that matches any route. /// /// This can be a useful building block to build new filters from, /// since [`Filter`](::Filter) is otherwise a sealed trait. /// /// # Example /// /// ``` /// use warp::Filter; /// /// let route = warp::any() /// .map(|| { /// "I always return this string!" /// }); /// ``` /// /// This could allow creating a single `impl Filter` returning a specific /// reply, that can then be used as the end of several different filter /// chains. /// /// Another use case is turning some clone-able resource into a `Filter`, /// thus allowing to easily `and` it together with others. /// /// ``` /// use std::sync::Arc; /// use warp::Filter; /// /// let state = Arc::new(vec![33, 41]); /// let with_state = warp::any().map(move || state.clone()); /// /// // Now we could `and` with any other filter: /// /// let route = warp::path::param() /// .and(with_state) /// .map(|param_id: u32, db: Arc<Vec<u32>>| { /// db.contains(¶m_id) /// }); /// ``` pub fn any() -> impl Filter<Extract=(), Error=Never> + Copy { Any } #[derive(Copy, Clone)] #[allow(missing_debug_implementations)] struct Any; impl FilterBase for Any { type Extract = (); type Error = Never; type Future = AnyFut; #[inline] fn filter(&self) -> Self::Future { AnyFut } } #[allow(missing_debug_implementations)] struct AnyFut; impl Future for AnyFut { type Item = (); type Error = Never; #[inline] fn poll(&mut self) -> Poll<Self::Item, Self::Error> { Ok(().into()) } }