puzz_route/
error.rs

1use std::fmt;
2
3use puzz_core::Request;
4
5#[derive(Debug)]
6pub struct NotFound {
7    request: Request,
8}
9
10impl NotFound {
11    pub fn new(request: Request) -> Self {
12        Self { request }
13    }
14
15    pub fn request_ref(&self) -> &Request {
16        &self.request
17    }
18
19    pub fn request_mut(&mut self) -> &mut Request {
20        &mut self.request
21    }
22
23    pub fn into_request(self) -> Request {
24        self.request
25    }
26}
27
28impl fmt::Display for NotFound {
29    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30        f.write_str("Not Found")
31    }
32}
33
34impl std::error::Error for NotFound {}
35
36#[derive(Debug)]
37pub struct MethodNotAllowed {
38    request: Request,
39}
40
41impl MethodNotAllowed {
42    pub fn new(request: Request) -> Self {
43        Self { request }
44    }
45
46    pub fn request_ref(&self) -> &Request {
47        &self.request
48    }
49
50    pub fn request_mut(&mut self) -> &mut Request {
51        &mut self.request
52    }
53
54    pub fn into_request(self) -> Request {
55        self.request
56    }
57}
58
59impl fmt::Display for MethodNotAllowed {
60    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
61        f.write_str("Method Not Allowed")
62    }
63}
64
65impl std::error::Error for MethodNotAllowed {}