hayro_syntax/object/
null.rs1use crate::object::Object;
4use crate::object::macros::object;
5use crate::reader::Reader;
6use crate::reader::{Readable, ReaderContext, Skippable};
7use core::fmt::{Display, Formatter};
8
9#[derive(Debug, Eq, PartialEq, Clone, Copy, Hash)]
11pub struct Null;
12
13impl Display for Null {
14 fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
15 f.write_str("null")
16 }
17}
18
19object!(Null, Null);
20
21impl Skippable for Null {
22 fn skip(r: &mut Reader<'_>, _: bool) -> Option<()> {
23 r.forward_tag(b"null")
24 }
25}
26
27impl Readable<'_> for Null {
28 fn read(r: &mut Reader<'_>, ctx: &ReaderContext<'_>) -> Option<Self> {
29 Self::skip(r, ctx.in_content_stream())?;
30
31 Some(Self)
32 }
33}
34
35#[cfg(test)]
36mod tests {
37 use crate::object::Null;
38 use crate::reader::Reader;
39 use crate::reader::ReaderExt;
40
41 #[test]
42 fn display() {
43 assert_eq!(format!("{}", Null), "null");
44 }
45
46 #[test]
47 fn null() {
48 assert_eq!(
49 Reader::new("null".as_bytes())
50 .read_without_context::<Null>()
51 .unwrap(),
52 Null
53 );
54 }
55
56 #[test]
57 fn null_trailing() {
58 assert_eq!(
59 Reader::new("nullabs".as_bytes())
60 .read_without_context::<Null>()
61 .unwrap(),
62 Null
63 );
64 }
65}