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/namespace resolution).
11    pub name: Cow<'de, str>,
12    /// Where the field resides (attribute/text/property/etc.).
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    /// Optional namespace URI (for XML namespace support).
21    pub namespace: Option<Cow<'de, str>>,
22}
23
24impl<'de> FieldEvidence<'de> {
25    /// Construct a new evidence entry.
26    pub fn new(
27        name: impl Into<Cow<'de, str>>,
28        location: FieldLocationHint,
29        value_type: Option<ValueTypeHint>,
30        namespace: Option<Cow<'de, str>>,
31    ) -> Self {
32        Self {
33            name: name.into(),
34            location,
35            value_type,
36            scalar_value: None,
37            namespace,
38        }
39    }
40
41    /// Construct a new evidence entry with a scalar value.
42    pub fn with_scalar_value(
43        name: impl Into<Cow<'de, str>>,
44        location: FieldLocationHint,
45        value_type: Option<ValueTypeHint>,
46        scalar_value: ScalarValue<'de>,
47        namespace: Option<Cow<'de, str>>,
48    ) -> Self {
49        Self {
50            name: name.into(),
51            location,
52            value_type,
53            scalar_value: Some(scalar_value),
54            namespace,
55        }
56    }
57}