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