51 lines
1.1 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-26 23:52:03 +08:00
#[derive(Clone, Debug)]
2021-06-25 23:53:13 +08:00
pub struct FlowyRequest {
id: String,
2021-06-26 23:52:03 +08:00
cmd: String,
2021-06-25 23:53:13 +08:00
}
impl FlowyRequest {
2021-06-26 23:52:03 +08:00
pub fn new(cmd: String) -> FlowyRequest {
Self {
id: uuid::Uuid::new_v4().to_string(),
cmd,
}
}
2021-06-25 23:53:13 +08:00
}
2021-06-24 23:37:45 +08:00
2021-06-26 23:52:03 +08:00
impl FlowyRequest {
pub fn get_cmd(&self) -> &str { &self.cmd }
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
}