use std::{slice::Iter, iter::Cloned}; use request::{FormItems, FormItem, Form, LenientForm, FromForm}; pub struct Query<'q>(pub &'q [FormItem<'q>]); impl<'q> IntoIterator for Query<'q> { type Item = FormItem<'q>; type IntoIter = Cloned>>; #[inline(always)] fn into_iter(self) -> Self::IntoIter { self.0.iter().cloned() } } pub trait FromQuery<'q>: Sized { type Error; fn from_query(q: Query<'q>) -> Result; } impl<'q, T: FromForm<'q>> FromQuery<'q> for Form { type Error = T::Error; #[inline] fn from_query(q: Query<'q>) -> Result { T::from_form(&mut FormItems::from(q.0), true).map(Form) } } impl<'q, T: FromForm<'q>> FromQuery<'q> for LenientForm { type Error = >::Error; #[inline] fn from_query(q: Query<'q>) -> Result { T::from_form(&mut FormItems::from(q.0), false).map(LenientForm) } } impl<'q, T: FromQuery<'q>> FromQuery<'q> for Option { type Error = !; #[inline] fn from_query(q: Query<'q>) -> Result { Ok(T::from_query(q).ok()) } } impl<'q, T: FromQuery<'q>> FromQuery<'q> for Result { type Error = !; #[inline] fn from_query(q: Query<'q>) -> Result { Ok(T::from_query(q)) } }