Skip to main content

facet_format/
evidence.rs

1extern crate alloc;
2
3use alloc::borrow::Cow;
4
5use crate::{FieldLocationHint, ScalarValue, ValueTypeHint};
6
7/// Evidence describing a serialized field encountered while probing input.
8#[derive(Debug, Clone, PartialEq)]
9pub struct FieldEvidence<'de> {
10    /// Serialized field name (after rename resolution).
11    pub name: Cow<'de, str>,
12    /// Where the field resides.
13    pub location: FieldLocationHint,
14    /// Optional type hint extracted from the wire (self-describing formats only).
15    pub value_type: Option<ValueTypeHint>,
16    /// Optional scalar value captured during probing.
17    /// This is used for value-based variant disambiguation (e.g., finding tag values).
18    /// Complex values (objects/arrays) are skipped and not captured here.
19    pub scalar_value: Option<ScalarValue<'de>>,
20}
21
22impl<'de> FieldEvidence<'de> {
23    /// Construct a new evidence entry.
24    pub fn new(
25        name: impl Into<Cow<'de, str>>,
26        location: FieldLocationHint,
27        value_type: Option<ValueTypeHint>,
28    ) -> Self {
29        Self {
30            name: name.into(),
31            location,
32            value_type,
33            scalar_value: None,
34        }
35    }
36
37    /// Construct a new evidence entry with a scalar value.
38    pub fn with_scalar_value(
39        name: impl Into<Cow<'de, str>>,
40        location: FieldLocationHint,
41        value_type: Option<ValueTypeHint>,
42        scalar_value: ScalarValue<'de>,
43    ) -> Self {
44        Self {
45            name: name.into(),
46            location,
47            value_type,
48            scalar_value: Some(scalar_value),
49        }
50    }
51}