hayro_syntax/object/
null.rs

1//! The null object.
2
3use crate::object::Object;
4use crate::object::macros::object;
5use crate::reader::{Readable, Reader, Skippable};
6use crate::xref::XRef;
7
8/// The null object.
9#[derive(Debug, Eq, PartialEq, Clone, Copy, Hash)]
10pub struct Null;
11
12object!(Null, Null);
13
14impl Skippable for Null {
15    fn skip<const PLAIN: bool>(r: &mut Reader) -> Option<()> {
16        r.forward_tag(b"null")
17    }
18}
19
20impl Readable<'_> for Null {
21    fn read<const PLAIN: bool>(r: &mut Reader, _: &XRef) -> Option<Self> {
22        Self::skip::<true>(r)?;
23
24        Some(Null)
25    }
26}
27
28#[cfg(test)]
29mod tests {
30    use crate::object::null::Null;
31    use crate::reader::Reader;
32
33    #[test]
34    fn null() {
35        assert_eq!(
36            Reader::new("null".as_bytes())
37                .read_without_xref::<Null>()
38                .unwrap(),
39            Null
40        );
41    }
42
43    #[test]
44    fn null_trailing() {
45        assert_eq!(
46            Reader::new("nullabs".as_bytes())
47                .read_without_xref::<Null>()
48                .unwrap(),
49            Null
50        );
51    }
52}