unityrs_core/walk/fields.rs
1//! Ordered class fields for language bindings. Incomplete reads keep their
2//! completed prefix so constructors can run before a later reader exception.
3use super::{Out, ReadDetail, ReadError};
4
5/// Progress of a binding's ordered object construction.
6#[derive(Default)]
7pub struct FieldProgress {
8 /// Number of fully read class dictionaries, in postorder.
9 pub completed: usize,
10 /// First reader failure, deferred until the completed prefix is constructed.
11 pub error: Option<ReadError>,
12 /// String descriptor of an unresolved reference, for the binding's
13 /// reader-specific diagnostic. These are shared slices of the input.
14 pub reference_names: Option<[crate::RawStr; 3]>,
15}
16
17const _: () = crate::send_sync::<FieldProgress>();
18
19impl FieldProgress {
20 pub(crate) fn recover(&mut self, error: ReadError) -> Result<Out, ReadError> {
21 if matches!(
22 error.detail,
23 ReadDetail::Limit(_) | ReadDetail::Charge(_) | ReadDetail::Tree(_)
24 ) {
25 return Err(error);
26 }
27 self.error.get_or_insert(error);
28 // The binding stops before visiting the incomplete suffix. This scalar
29 // carries no allocation and is never exposed as an object field.
30 Ok(Out::Plain(crate::Value::Int(0)))
31 }
32
33 pub(crate) fn finish_class(&mut self) {
34 if self.error.is_none() {
35 self.completed += 1;
36 }
37 }
38}