Amazon Ion Schema Rust
An implementation of Amazon Ion Schema in Rust.
If you want to try out a web tool to validate your Ion values using ion-schema-rust, please visit: https://amazon-ion.github.io/ion-schema/sandbox
This package is considered experimental, under active/early development, and the API is subject to change.
Getting Started
The following rust code sample is a simple example of how to use this API.
Example schema my_schema.isl
This file (my_schema.isl) defines a new type (my_int_type) based on Ion's int type.
schema_header::{
imports: [],
}
type::{
name: my_int_type,
type: int,
}
schema_footer::{
}
Loading a schema and validating an Ion value
use Element;
use ;
use ;
use Schema;
use SchemaSystem;
use TypeDefinition;
use IonSchemaElement;
use Debug;
use Path;
use Arc;
// Verify if the given value is valid and print violation for invalid value
Output
When run, the code above produces the following output:
5e3
Violation {
constraint: "my_int_type",
code: TypeConstraintsUnsatisfied,
message: "value didn't satisfy type constraint(s)",
ion_path: (),
violations: [
Violation {
constraint: "type_constraint",
code: TypeMismatched,
message: "expected type Int, found Float",
ion_path: (),
violations: [],
},
],
}
/* Ion document */ 5 true 6e3 /* end */
Violation {
constraint: "my_int_type",
code: TypeConstraintsUnsatisfied,
message: "value didn't satisfy type constraint(s)",
ion_path: (),
violations: [
Violation {
constraint: "type_constraint",
code: TypeMismatched,
message: "expected type Int, found document",
ion_path: (),
violations: [],
},
],
}
For more getting started examples, please visit: https://amazon-ion.github.io/ion-schema/docs/cookbook/ion-schema-rust-getting-started
Development
This repository contains git submodules
called ion-schema-schemas and ion-schema-tests, which holds test data used by
this library's unit tests.
The easiest way to clone the ion-schema-rust repository and initialize its submodules
is to run the following command:
Alternatively, the submodule may be initialized independently from the clone by running the following commands:
Building the project,
Running all tests for ion-schema-rust,
Examples
The repository contains an examples/ folder which is a CLI tool to load and validate schema.
To load a schema using the examples CLI:
To validate an ion value against a schema type using the examples CLI:
For more information on how to use the examples CLI, run the following command:
License
This library is licensed under the Apache-2.0 License.