qualia_core_db/nlp/contracts/
error.rs1use core::fmt;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
12#[repr(u8)]
13pub enum AnalysisState {
14 Complete = 0,
15 Partial = 1,
16 Unsupported = 2,
17 NotRequested = 3,
18 BudgetExceeded = 4,
19 Cancelled = 5,
20 InvalidInput = 6,
21}
22
23#[derive(Debug, Clone, Copy, PartialEq, Eq)]
25#[repr(u8)]
26pub enum BufferChannel {
27 Tokens = 0,
28 Sentences = 1,
29 Hits = 2,
30 Norms = 3,
31 Plans = 4,
32}
33
34#[derive(Debug, Clone, Copy, PartialEq, Eq)]
36pub enum NlpContractError {
37 SourceTooLarge {
38 bytes: usize,
39 max: usize,
40 },
41 OutputBufferFull {
42 needed: usize,
43 capacity: usize,
44 channel: BufferChannel,
45 },
46 SpanInvalid {
47 start: u32,
48 end: u32,
49 },
50}
51
52impl fmt::Display for NlpContractError {
53 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
54 match *self {
55 Self::SourceTooLarge { bytes, max } => {
56 write!(f, "NLP source is {bytes} bytes; max is {max}")
57 }
58 Self::OutputBufferFull {
59 needed,
60 capacity,
61 channel,
62 } => write!(
63 f,
64 "NLP {channel:?} buffer needs {needed} slots; had {capacity}"
65 ),
66 Self::SpanInvalid { start, end } => {
67 write!(f, "NLP span {start}..{end} is not a UTF-8 source slice")
68 }
69 }
70 }
71}
72
73impl std::error::Error for NlpContractError {}