44 lines
1.0 KiB
Rust
Raw Normal View History

2021-06-25 23:53:13 +08:00
use std::future::Future;
2021-06-24 23:37:45 +08:00
use crate::{
2021-06-25 23:53:13 +08:00
error::SystemError,
request::payload::Payload,
2021-06-24 23:37:45 +08:00
util::ready::{ready, Ready},
};
2021-06-25 23:53:13 +08:00
use std::hash::Hash;
2021-06-24 23:37:45 +08:00
2021-06-25 23:53:13 +08:00
pub struct FlowyRequest {
id: String,
}
impl FlowyRequest {
pub fn get_id(&self) -> &str { &self.id }
}
2021-06-24 23:37:45 +08:00
impl std::default::Default for FlowyRequest {
2021-06-25 23:53:13 +08:00
fn default() -> Self { Self { id: "".to_string() } }
2021-06-24 23:37:45 +08:00
}
pub trait FromRequest: Sized {
2021-06-25 23:53:13 +08:00
type Error: Into<SystemError>;
2021-06-24 23:37:45 +08:00
type Future: Future<Output = Result<Self, Self::Error>>;
fn from_request(req: &FlowyRequest, payload: &mut Payload) -> Self::Future;
}
#[doc(hidden)]
impl FromRequest for () {
2021-06-25 23:53:13 +08:00
type Error = SystemError;
type Future = Ready<Result<(), SystemError>>;
2021-06-24 23:37:45 +08:00
2021-06-25 23:53:13 +08:00
fn from_request(_req: &FlowyRequest, _payload: &mut Payload) -> Self::Future { ready(Ok(())) }
2021-06-24 23:37:45 +08:00
}
#[doc(hidden)]
impl FromRequest for String {
2021-06-25 23:53:13 +08:00
type Error = SystemError;
type Future = Ready<Result<String, SystemError>>;
2021-06-24 23:37:45 +08:00
2021-06-25 23:53:13 +08:00
fn from_request(_req: &FlowyRequest, _payload: &mut Payload) -> Self::Future { ready(Ok("".to_string())) }
2021-06-24 23:37:45 +08:00
}