rust_web_server/null/
mod.rs1#[cfg(test)]
2mod tests;
3
4use std::fmt::{Debug, Display, Formatter};
5use std::str::FromStr;
6use crate::core::New;
7
8pub const NULL: &'static Null = &Null{};
9
10pub struct Null {}
11
12pub struct ParseNullError {
13 pub message: String
14}
15
16impl Debug for ParseNullError {
17 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
18 f.write_str(&self.message)
19 }
20}
21
22impl Display for Null {
23 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
24 f.write_str("null")
25 }
26}
27
28impl PartialEq for Null {
29 fn eq(&self, _other: &Self) -> bool {
30 true
31 }
32}
33
34impl Debug for Null {
35 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
36 f.write_str("null")
37 }
38}
39
40impl New for Null {
41 fn new() -> Self {
42 Null{}
43 }
44}
45
46impl Clone for Null {
47 fn clone(&self) -> Self {
48 Null::new()
49 }
50}
51
52impl FromStr for Null {
53 type Err = ParseNullError;
54
55 fn from_str(null: &str) -> Result<Self, Self::Err> {
56 if null.trim() != "null" {
57 let message = format!("error parsing null: {}", null);
58 return Err(ParseNullError { message })
59 }
60 Ok(Null::new())
61 }
62}