amazon-ion / ion-schema-rust

Rust implementation of Ion Schema
https://amazon-ion.github.io/ion-schema/sandbox
Apache License 2.0
13 stars 6 forks source link

Create single resuable method to resolve type references for `Constraint` implementations #44

Open desaikd opened 3 years ago

desaikd commented 3 years ago

Constraint implementations (i.e. structs like AllOf, AnyOf, Type, ...) have common functionalities that could be converted to a separate reusable method to remove duplicate code in these implementations.

This can be added in the Constraint implementation itself so that any Constraint variant can use this method.

impl Constraint { 
     fn resolve_type_references(
         type_references: &[IslTypeRef],
         type_store: &mut TypeStore,
         pending_types: &mut PendingTypes
     ) -> IonSchemaResult<Vec<TypeId>> {
            type_references
            .iter()
            .map(|t| IslTypeRef::resolve_type_reference(t, type_store, pending_types))
            .collect::<IonSchemaResult<Vec<TypeId>>>()?;
    }
}