bolt_web/
types.rs

1use std::collections::HashMap;
2
3use crate::{request::RequestBody, response::ResponseWriter};
4use async_trait::async_trait;
5
6#[derive(Hash, Eq, PartialEq, Debug, Clone, Copy)]
7pub enum Method {
8    GET,
9    POST,
10    PUT,
11    PATCH,
12    DELETE,
13    OPTIONS,
14    HEAD,
15    TRACE,
16}
17
18#[derive(Eq, PartialEq)]
19#[allow(dead_code)]
20pub enum Mode {
21    Http1,
22    Http2,
23}
24
25#[async_trait]
26pub trait Middleware: Send + Sync {
27    async fn run(&self, req: &mut RequestBody, res: &mut ResponseWriter);
28}
29
30#[async_trait]
31pub trait ErrorHandler: Send + Sync {
32    async fn run(&self, msg: String, res: &mut ResponseWriter);
33}
34
35#[async_trait]
36pub trait Handler: Send + Sync {
37    async fn handle(&self, req: &mut RequestBody, res: &mut ResponseWriter);
38}
39
40#[allow(dead_code)]
41#[derive(Debug, Clone)]
42pub struct FormFile {
43    pub field_name: String,
44    pub file_name: String,
45    pub content_type: String,
46    pub temp_path: String,
47}
48
49#[derive(Debug, Clone)]
50pub struct FormData {
51    pub files: Vec<FormFile>,
52    pub fields: HashMap<String, String>,
53}
54
55#[allow(dead_code)]
56pub type BoltError = Box<dyn std::error::Error + Send + Sync>;
57
58#[allow(dead_code)]
59pub type BoltResult<T> = Result<T, BoltError>;