zon_util 0.0.2

part of a new WIP, very incomplete async http service stack
Documentation
use std::{
    convert::Infallible,
    ops::{Deref, DerefMut},
};

use serde::de::DeserializeOwned;
use zon_core::{FromRequestParts, RequestParts};

#[derive(Clone, Copy, Debug, Default)]
pub struct Query<T>(pub T);

impl<T> FromRequestParts for Query<T>
where
    T: DeserializeOwned + Send,
{
    type Rejection = Infallible; // FIXME

    fn from_request_parts(
        parts: &mut RequestParts,
    ) -> impl std::future::Future<Output = Result<Self, Self::Rejection>> + Send {
        let query = parts.uri.query().unwrap_or("");
        async move { Ok(Self(serde_html_form::from_str(query).expect("FIXME: Add QueryRejection"))) }
    }
}

impl<T> Deref for Query<T> {
    type Target = T;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

impl<T> DerefMut for Query<T> {
    fn deref_mut(&mut self) -> &mut Self::Target {
        &mut self.0
    }
}