abin/common/segment.rs
1/// Some sort of segment that knows its length (in bytes). It's used for constructing
2/// binaries/strings efficiently (knowing the entire length in advance to avoid
3/// re-allocations).
4pub trait Segment {
5 /// The number of bytes in this segment.
6 fn number_of_bytes(&self) -> usize;
7
8 /// Same as `number_of_bytes==0`.
9 #[inline]
10 fn is_empty(&self) -> bool {
11 self.number_of_bytes() == 0
12 }
13
14 /// Constructs an empty-segment (`number_of_bytes` is 0).
15 fn empty() -> Self;
16}