amazon-ion / ion-schema-rust

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

Use version marker trait for ISL model #187

Open desaikd opened 1 year ago

desaikd commented 1 year ago

Current APIs for creating an ISL model allows mixing different versioned ISL constraints. When we try to resolve this ISL model by loading the schema(load_schema()) it returns error if the constraints are from different ISL versions. If we have something that returns a compile-time error while constructing the ISL model that gives an ease of use for the API.

We can create a marker trait for ISL versioning and have it implement for different ISL versions. e.g.

trait IslVersion {} // ISL version marker trait

struct IslV1_0 {}
struct IslV2_0 {}

This can be used to define ISL model structs over the generic marker trait IslVersion. We can then have a particular version struct implementation for a constraint. This allows us to define constraints based on its version and gives a compile time error when a constraint doesn't exist for the given ISL version.