codeq/span/
mod.rs

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
mod offset;
mod size;

pub use offset::Offset;
pub use size::Size;

/// A trait for types that span a range with an offset and size
pub trait Span {
    /// Returns the starting offset of the span
    fn offset(&self) -> Offset;

    /// Returns the size of the span
    fn size(&self) -> Size;

    /// Returns the starting offset of the span.
    /// This is an alias for [`offset()`](Self::offset).
    fn start(&self) -> Offset {
        self.offset()
    }

    /// Returns the end offset of the span (offset + size)
    fn end(&self) -> Offset {
        self.offset() + self.size()
    }
}

impl<T> Span for &T
where T: Span
{
    fn offset(&self) -> Offset {
        (*self).offset()
    }

    fn size(&self) -> Size {
        (*self).size()
    }
}