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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use crate::index::{Index, Indexes, Length};

/// The empty [Index] implementation.
///
/// This can be used in combination with [`Builder::new_with`] to ensure that
/// that tree does not store any information on spans, reducing overhead if this
/// is not necessary.
///
/// [`Builder::new_with`]: crate::Builder::new_with
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct Empty;

impl From<u32> for Empty {
    fn from(_: u32) -> Self {
        Empty
    }
}

impl From<usize> for Empty {
    fn from(_: usize) -> Self {
        Empty
    }
}

impl Index for Empty {
    const EMPTY: Self = Empty;

    type Indexes<P> = Empty;
    type Length = Empty;

    #[inline]
    fn is_empty(&self) -> bool {
        true
    }

    #[inline]
    fn as_usize(self) -> usize {
        0
    }

    #[inline]
    fn checked_add_len(self, _: Self::Length) -> Option<Self> {
        Some(Empty)
    }

    #[inline]
    fn len_to(self, _: Self) -> Self {
        Empty
    }

    #[inline]
    fn from_usize(_: usize) -> Option<Self> {
        Some(Empty)
    }
}

impl From<Empty> for usize {
    #[inline]
    fn from(Empty: Empty) -> Self {
        0
    }
}

impl<I, P> Indexes<I, P> for Empty {
    const EMPTY: Self = Self;

    #[inline]
    fn push(&mut self, _: I, _: P) {}

    #[inline]
    fn binary_search(&self, _: I) -> Result<usize, usize> {
        Err(0)
    }

    #[inline]
    fn get(&self, _: usize) -> Option<&P> {
        None
    }
}

impl Length for Empty {
    const EMPTY: Self = Empty;

    #[inline]
    fn is_empty(&self) -> bool {
        true
    }
}