ProbingSolver

Struct ProbingSolver 

Source
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:

  1. Deserializer scans keys (without parsing values) and reports them
  2. Solver filters candidates based on which configs have that key path
  3. Once one candidate remains, solver returns Solved
  4. 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>

Source

pub fn new(schema: &'a Schema) -> Self

Create a new probing solver from a schema.

Source

pub fn from_configurations(configs: &'a [Configuration]) -> Self

Create a new probing solver from configurations directly.

Source

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.

Source

pub fn candidates(&self) -> &[&'a Configuration]

Get the current candidate configurations.

Source

pub fn finish(&self) -> ProbeResult<'a>

Finish probing - returns Solved if exactly one candidate remains.

Trait Implementations§

Source§

impl<'a> Debug for ProbingSolver<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.