pub struct TaggedEnumSchema<F>{
pub tag_field: &'static str,
pub valid_tags: &'static [&'static str],
pub fields_for_tag: F,
pub enum_arrays: Vec<(&'static str, &'static [&'static str])>,
pub nested_objects: Vec<(&'static str, &'static [&'static str])>,
}Expand description
Schema for a tagged enum (discriminated union)
Used for types with a discriminator field (e.g., tag: “type”, “kind”)
§Example
use fuzzy_parser::TaggedEnumSchema;
let schema = TaggedEnumSchema::new(
"type",
&["AddDerive", "RemoveDerive"],
|tag| match tag {
"AddDerive" | "RemoveDerive" => Some(&["target", "derives"][..]),
_ => None,
},
)
.with_enum_array("derives", &["Debug", "Clone", "Serialize"])
.with_nested_object("config", &["timeout", "retries"]);Fields§
§tag_field: &'static strThe discriminator field name (e.g., “type”, “kind”)
Valid tag values (e.g., [“AddDerive”, “RenameIdent”, …])
fields_for_tag: FFunction to get valid fields for a given tag value
enum_arrays: Vec<(&'static str, &'static [&'static str])>Fields that contain arrays of enum values: (field_name, valid_values)
nested_objects: Vec<(&'static str, &'static [&'static str])>Fields that contain nested objects: (field_name, valid_fields)
Implementations§
Source§impl<F> TaggedEnumSchema<F>
impl<F> TaggedEnumSchema<F>
Sourcepub fn new(
tag_field: &'static str,
valid_tags: &'static [&'static str],
fields_for_tag: F,
) -> TaggedEnumSchema<F>
pub fn new( tag_field: &'static str, valid_tags: &'static [&'static str], fields_for_tag: F, ) -> TaggedEnumSchema<F>
Create a new tagged enum schema
Sourcepub fn with_enum_array(
self,
field: &'static str,
valid_values: &'static [&'static str],
) -> TaggedEnumSchema<F>
pub fn with_enum_array( self, field: &'static str, valid_values: &'static [&'static str], ) -> TaggedEnumSchema<F>
Add an enum array field for repair
Values in this array field will be fuzzy-matched against valid_values.
§Example
use fuzzy_parser::TaggedEnumSchema;
let schema = TaggedEnumSchema::new("type", &["AddDerive"], |_| Some(&["derives"][..]))
.with_enum_array("derives", &["Debug", "Clone", "Serialize"]);
// Now "Debg" in derives array will be corrected to "Debug"Sourcepub fn with_nested_object(
self,
field: &'static str,
valid_fields: &'static [&'static str],
) -> TaggedEnumSchema<F>
pub fn with_nested_object( self, field: &'static str, valid_fields: &'static [&'static str], ) -> TaggedEnumSchema<F>
Add a nested object field for repair
Field names in this nested object will be fuzzy-matched against valid_fields.
§Example
use fuzzy_parser::TaggedEnumSchema;
let schema = TaggedEnumSchema::new("type", &["Configure"], |_| Some(&["config"][..]))
.with_nested_object("config", &["timeout", "retries", "enabled"]);
// Now "timout" in config object will be corrected to "timeout"Sourcepub fn is_valid_tag(&self, tag: &str) -> bool
pub fn is_valid_tag(&self, tag: &str) -> bool
Check if a tag value is valid
Sourcepub fn get_fields(&self, tag: &str) -> Option<&'static [&'static str]>
pub fn get_fields(&self, tag: &str) -> Option<&'static [&'static str]>
Get valid fields for a tag value
Sourcepub fn get_enum_array_values(
&self,
field: &str,
) -> Option<&'static [&'static str]>
pub fn get_enum_array_values( &self, field: &str, ) -> Option<&'static [&'static str]>
Get valid enum values for an array field
Sourcepub fn get_nested_object_fields(
&self,
field: &str,
) -> Option<&'static [&'static str]>
pub fn get_nested_object_fields( &self, field: &str, ) -> Option<&'static [&'static str]>
Get valid fields for a nested object