Skip to main content

FieldResolver

Struct FieldResolver 

Source
pub struct FieldResolver { /* private fields */ }
Expand description

Resolves fixture field paths to language-specific accessor expressions.

Implementations§

Source§

impl FieldResolver

Source

pub fn new( fields: &HashMap<String, String>, optional: &HashSet<String>, result_fields: &HashSet<String>, array_fields: &HashSet<String>, method_calls: &HashSet<String>, ) -> Self

Create a new resolver from the e2e config’s fields aliases, fields_optional set, result_fields set, fields_array set, and fields_method_calls set.

Source

pub fn new_with_error_aliases( fields: &HashMap<String, String>, optional: &HashSet<String>, result_fields: &HashSet<String>, array_fields: &HashSet<String>, method_calls: &HashSet<String>, error_field_aliases: &HashMap<String, String>, ) -> Self

Create a new resolver that also includes error-path field aliases.

error_field_aliases maps fixture sub-field names (the part after "error.") to the actual field names on the error type, enabling accessor_for_error to resolve fields like "status_code" against the error value.

Source

pub fn new_with_php_getters( fields: &HashMap<String, String>, optional: &HashSet<String>, result_fields: &HashSet<String>, array_fields: &HashSet<String>, method_calls: &HashSet<String>, error_field_aliases: &HashMap<String, String>, php_getter_map: PhpGetterMap, ) -> Self

Create a new resolver that also knows which PHP fields need getter-method syntax.

php_getter_map carries a per-(type_name, field_name) classification: the PHP accessor renderer emits ->getCamelCase() when (owner_type, field) is recorded as needing a getter, and ->camelCase property syntax otherwise. This matches the ext-php-rs 0.15.x behaviour where #[php(getter)] is used for non-scalar fields (Named structs, Vec, Map, etc.) while #[php(prop)] is used for scalar-compatible fields.

Keying by (type, field) — not bare field name — is essential because the same field name can have different scalarness on different types. The map also carries per-type field→nested-type mappings so the renderer can walk a path like outer.inner.content through the IR, advancing the current-type cursor at each segment.

Source

pub fn with_swift_root_type(&self, root_type: Option<String>) -> Self

Return a clone of this resolver with the Swift first-class map’s root_type replaced.

Used by Swift e2e codegen to thread a per-fixture (per-call) root type into the render_swift_with_first_class_map dispatcher. Each fixture’s call returns a different IR type (e.g. ChatCompletionResponse vs FileObject), and the first-class/opaque classification of the root drives whether path segments are emitted with property access or method-call access. Setting it per-fixture avoids picking a single workspace-wide default that breaks half the fixtures.

Source

pub fn new_with_swift_first_class( fields: &HashMap<String, String>, optional: &HashSet<String>, result_fields: &HashSet<String>, array_fields: &HashSet<String>, method_calls: &HashSet<String>, error_field_aliases: &HashMap<String, String>, swift_first_class_map: SwiftFirstClassMap, ) -> Self

Create a new resolver that also knows the Swift first-class/opaque classification per IR type. Mirrors new_with_php_getters but for the Swift render_swift_with_first_class_map path.

Source

pub fn resolve<'a>(&'a self, fixture_field: &'a str) -> &'a str

Resolve a fixture field path to the actual struct path. Falls back to the field itself if no alias exists.

Source

pub fn leaf_is_vec_via_swift_map(&self, field: &str) -> bool

True when the leaf segment of field is a Vec<T> field on any IR type.

Used by swift codegen to keep .count straight on method-call accessors (result.output() returns RustVec — .count works directly, no .toString() needed). The check is on the bare leaf name, so it is best- effort when distinct types share a field name with different kinds.

Source

pub fn is_optional(&self, field: &str) -> bool

Check if a resolved field path is optional.

Source

pub fn has_alias(&self, fixture_field: &str) -> bool

Check if a fixture field has an explicit alias mapping.

Source

pub fn has_explicit_field(&self, field_name: &str) -> bool

Check whether field_name is configured as an explicit result field.

Returns true only when the caller has populated result_fields AND the field name is present. Empty result_fields always returns false — use is_valid_for_result for the default-allow semantics.

Source

pub fn is_valid_for_result(&self, fixture_field: &str) -> bool

Check whether a fixture field path is valid for the configured result type.

Source

pub fn is_array(&self, field: &str) -> bool

Check if a resolved field is an array/Vec type.

Source

pub fn is_collection_root(&self, field: &str) -> bool

Check if a field name is the root of a collection type (i.e., the field itself returns a Vec/array, even though it is not in fields_array directly).

fields_array tracks traversal paths like choices[0].message.tool_calls — the array element paths — not the bare collection accessor (choices). fields_optional may also contain paths like data[0].url that reveal data is a collection root.

Returns true when any entry in array_fields or optional_fields starts with {field}[, indicating that field is the top-level collection getter.

Source

pub fn tagged_union_split( &self, fixture_field: &str, ) -> Option<(String, String, String)>

Check if a resolved field path traverses a tagged-union variant.

Returns Some((prefix, variant, suffix)) where:

  • prefix is the path up to (but not including) the tagged-union field (e.g., "metadata.format")
  • variant is the tagged-union accessor segment (e.g., "excel")
  • suffix is the remaining path after the variant (e.g., "sheet_count")

Returns None if no tagged-union segment exists in the path.

Source

pub fn has_map_access(&self, fixture_field: &str) -> bool

Check if a resolved field path contains a non-numeric map access.

Source

pub fn accessor( &self, fixture_field: &str, language: &str, result_var: &str, ) -> String

Generate a language-specific accessor expression.

Source

pub fn accessor_for_error( &self, sub_field: &str, language: &str, err_var: &str, ) -> String

Generate a language-specific accessor expression for an error-path field.

Used when assertion_type == "error" and the fixture declares a field like "error.status_code". The caller strips the "error." prefix and passes the sub-field name (e.g. "status_code") here.

Resolves against error_field_aliases (instead of the success-path aliases). Falls back to direct field access (i.e. err_var.status_code) when no alias exists.

For Rust, uses render_rust_with_optionals so that fields in method_calls emit parentheses (e.g. err.status_code() when "status_code" is in fields_method_calls).

Source

pub fn has_error_aliases(&self) -> bool

Check whether a sub-field (the part after "error.") has an entry in error_field_aliases or if there are any error aliases at all.

When there are no error aliases configured, callers fall back to direct field access, which is the safe default for known public fields like status_code on LiterLlmError.

Source

pub fn rust_unwrap_binding( &self, fixture_field: &str, result_var: &str, ) -> Option<(String, String)>

Generate a Rust variable binding that unwraps an Optional string field.

Trait Implementations§

Source§

impl Clone for FieldResolver

Source§

fn clone(&self) -> FieldResolver

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more