qualia_core_db/q42/chebi_parse/record.rs
1//! Normalized ChEBI compound records (AST-03).
2
3/// One accepted ChEBI compound row from `compounds.tsv`.
4///
5/// Cold-construction type: heap `String` fields are intentional. Hot-path Quin
6/// projection belongs to AST-04 and must not allocate URI strings at runtime.
7#[derive(Debug, Clone, PartialEq, Eq)]
8pub struct ChebiRecord {
9 /// Numeric ChEBI id (e.g. `15377`).
10 pub id: u64,
11 /// Upstream status code preserved as text (`C` / `E` / …). Deleted (`D`)
12 /// rows never appear here — they are quarantined.
13 pub status: String,
14 /// Accession string (e.g. `CHEBI:15377`).
15 pub accession: String,
16 /// Free-text SOURCE column (may be empty).
17 pub source: String,
18 /// Parent compound id, or `None` when the PARENT_ID cell is empty.
19 pub parent_id: Option<u64>,
20 /// Compound display name (non-empty for accepted rows).
21 pub name: String,
22 /// Definition text (may be empty).
23 pub definition: String,
24 /// 1-based file line number for provenance (header is line 1).
25 pub source_line: u64,
26}
27
28/// Caller-supplied parse ceilings for one compounds.tsv pass.
29#[derive(Debug, Clone, Copy, PartialEq, Eq)]
30pub struct ParseBudgets {
31 /// Reject the whole input when `input.len()` exceeds this.
32 pub max_bytes: u64,
33 /// Combined ceiling for accepted + quarantined rows.
34 pub max_records: u64,
35 /// Reject when any single line (excluding the trailing newline) exceeds this.
36 pub max_line_bytes: u64,
37}
38
39impl ParseBudgets {
40 /// Validate positivity of all budget fields.
41 pub fn validate(self) -> Result<Self, super::error::ParseError> {
42 if self.max_bytes == 0 || self.max_records == 0 || self.max_line_bytes == 0 {
43 return Err(super::error::ParseError::InvalidBudgets);
44 }
45 Ok(self)
46 }
47}
48
49/// Result of a successful (possibly partially quarantined) parse pass.
50#[derive(Debug, Clone, PartialEq, Eq)]
51pub struct ParseReport {
52 pub accepted: Vec<ChebiRecord>,
53 pub quarantined: Vec<super::error::QuarantinedRow>,
54 pub bytes_read: u64,
55 /// Caller-supplied release attribution copied verbatim into the report.
56 pub release_label: String,
57}
58
59impl ParseReport {
60 /// Total rows that consumed record budget (accepted + quarantined).
61 pub fn total_rows(&self) -> u64 {
62 (self.accepted.len() + self.quarantined.len()) as u64
63 }
64}