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
//! One identified source and its scan report.
use crate::ScanReport;
/// Result produced for one identified UTF-8 source.
///
/// `K` is supplied by the caller and can be a file path, editor-buffer ID,
/// database key or any other source identifier. The scanner never interprets
/// the key.
///
/// The entry stores the original UTF-8 byte length so aggregate APIs can report
/// how much text was scanned without retaining the source itself.
#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ScanEntry<K> {
key: K,
source_bytes: usize,
report: ScanReport,
}
impl<K> ScanEntry<K> {
pub(crate) const fn new(key: K, source_bytes: usize, report: ScanReport) -> Self {
Self {
key,
source_bytes,
report,
}
}
/// Returns the caller-supplied source identifier.
#[must_use]
pub const fn key(&self) -> &K {
&self.key
}
/// Returns the UTF-8 byte length of the scanned source.
#[must_use]
pub const fn source_bytes(&self) -> usize {
self.source_bytes
}
/// Returns the immutable report for this source.
#[must_use]
pub const fn report(&self) -> &ScanReport {
&self.report
}
/// Consumes this entry and returns its components.
#[must_use]
pub fn into_parts(self) -> (K, usize, ScanReport) {
(self.key, self.source_bytes, self.report)
}
}