zarrs_conventions
An implementation of zarr-conventions for zarrs ecosystem.
The main crate is zarrs_conventions;
this repository also includes some specific conventions.
Usage
Defining a convention convention
use ;
// re-exported crates
use ;
/// Example from the conventions spec:
/// <https://github.com/zarr-conventions/zarr-conventions-spec>
// Allows the type to be represented in `{ ..., "attributes": { ..., "proj:code": "mycode" } }` form.
// Optional (so long as NestedRepr is implemented).
// Allows the type to be represented in `{ ..., "attributes": { ..., "proj": { "code": "mycode" } } }` form.
// Optional (so long as PrefixedRepr is implemented).
// Allow this convention to be discovered at runtime by importers of this module.
// Not strictly necessary.
register_zarr_conventions!;
Working with conventional metadata
use ;
use ;
// From the `"attributes"` field of Zarr v3 metadata.
// The full metadata document may look like
// `{ "zarr_format": 3, "node_type": "group", "attributes": ... }`
let attributes = json!;
// Assume these types are fully defined and have the appropriate *Repr traits implemented.
;
;
;
// We don't have to define the final "something_else" convention; the parser will just treat it as unstructured.
let parser: AttributesParser = from_value;
// Ok(None) if the requested convention is not listed in zarr_conventions.
// Err if it is, but cannot be deserialised.
let maybe_nested: = parser.parse_nested.unwrap;
let maybe_prefixed: = parser.parse_prefixed.unwrap;
let maybe_either: = parser.parse.unwrap;
// Unstructured attributes can still be retrieved.
let other_value: = parser.get.unwrap;
// Prepare to write metadata
let builder = default;
// Disable writing of the name and description in zarr_conventions,
// to keep the length down.
// At least one of uuid, spec_url, schema_url must remain true.
builder.name.description;
// The list of zarr_conventions will be populated automatically
// when conventional metadata is added.
builder.add_nested.unwrap;
builder.add_prefixed.unwrap;
// For conventional metadata which can be represented either way,
// you have to pick one when serialising.
builder.add_nested.unwrap;
// You can add arbitrary attributes
builder.add_attribute.unwrap;
let value = builder.build.unwrap;
println!;