Tuples

The TupleType can be used to represent a fixed list of heterogeneous values of a given type, as defined by items_types.

#![allow(unused)]
fn main() {
use schematic::{Schematic, Schema, SchemaBuilder, SchemaType, schema::{TupleType, IntegerKind}};

impl Schematic for T {
	fn build_schema(mut schema: SchemaBuilder) -> Schema {
		schema.tuple(TupleType {
			items_types: vec![
				Box::new(schema.infer::<String>()),
				Box::new(schema.infer::<bool>()),
				Box::new(schema.nest().integer(IntegerType::new_kind(IntegerKind::U32))),
			],
			..TupleType::default()
		})
	}
}
}

If you’re only defining the items_types field, you can use the shorthand TupleType::new() method. When using this approach, the Boxs are automatically inserted for you.

#![allow(unused)]
fn main() {
schema.tuple(TupleType::new([
	schema.infer::<String>(),
	schema.infer::<bool>(),
	schema.nest().integer(IntegerType::new_kind(IntegerKind::U32)),
]));
}

Automatically implemented for tuples of 0-12 length.