hayro_syntax/object/
null.rs

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