pub struct ProbingSolver<'a> { /* private fields */ }Expand description
Depth-aware probing solver for streaming deserialization.
Unlike the batch solver or incremental solver, this solver accepts key reports at arbitrary depths. It’s designed for the “peek” strategy:
- Deserializer scans keys (without parsing values) and reports them
- Solver filters candidates based on which configs have that key path
- Once one candidate remains, solver returns
Solved - Deserializer rewinds and parses into the resolved type
§Example
use facet::Facet;
use facet_solver::{Schema, ProbingSolver, ProbeResult};
#[derive(Facet)]
struct TextPayload { content: String }
#[derive(Facet)]
struct BinaryPayload { bytes: Vec<u8> }
#[derive(Facet)]
#[repr(u8)]
enum MessageKind {
Text { payload: TextPayload },
Binary { payload: BinaryPayload },
}
#[derive(Facet)]
struct Message {
id: String,
#[facet(flatten)]
kind: MessageKind,
}
let schema = Schema::build(Message::SHAPE).unwrap();
let mut solver = ProbingSolver::new(&schema);
// "id" exists in both configs - keep going
assert!(matches!(solver.probe_key(&[], "id"), ProbeResult::KeepGoing));
// "payload" exists in both configs - keep going
assert!(matches!(solver.probe_key(&[], "payload"), ProbeResult::KeepGoing));
// "content" inside payload only exists in Text - solved!
match solver.probe_key(&["payload"], "content") {
ProbeResult::Solved(config) => {
assert!(config.has_key_path(&["payload", "content"]));
}
_ => panic!("expected Solved"),
}Implementations§
Source§impl<'a> ProbingSolver<'a>
impl<'a> ProbingSolver<'a>
Sourcepub fn from_configurations(configs: &'a [Configuration]) -> Self
pub fn from_configurations(configs: &'a [Configuration]) -> Self
Create a new probing solver from configurations directly.
Sourcepub fn probe_key(&mut self, path: &[&str], key: &str) -> ProbeResult<'a>
pub fn probe_key(&mut self, path: &[&str], key: &str) -> ProbeResult<'a>
Report a key found at a path during probing.
path: The ancestor keys (e.g.,["payload"]when inside the payload object)key: The key found at this level (e.g.,"content")
Returns what to do next.
Sourcepub fn candidates(&self) -> &[&'a Configuration]
pub fn candidates(&self) -> &[&'a Configuration]
Get the current candidate configurations.
Sourcepub fn finish(&self) -> ProbeResult<'a>
pub fn finish(&self) -> ProbeResult<'a>
Finish probing - returns Solved if exactly one candidate remains.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for ProbingSolver<'a>
impl<'a> RefUnwindSafe for ProbingSolver<'a>
impl<'a> Send for ProbingSolver<'a>
impl<'a> Sync for ProbingSolver<'a>
impl<'a> Unpin for ProbingSolver<'a>
impl<'a> UnwindSafe for ProbingSolver<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more