stac_validate/
lib.rs

1//! Validate STAC objects with [json-schema](https://json-schema.org/).
2//!
3//! # Examples
4//!
5//! Validation is provided via the [Validate] trait:
6//!
7//! ```
8//! use stac::Item;
9//! use stac_validate::Validate;
10//!
11//! # tokio_test::block_on(async {
12//! Item::new("an-id").validate().await.unwrap();
13//! # })
14//! ```
15//!
16//! If you're working in a blocking context (not async), enable the `blocking` feature and use [ValidateBlocking]:
17//!
18//! ```
19//! # use stac::Item;
20//! #[cfg(feature = "blocking")]
21//! {
22//!     use stac_validate::ValidateBlocking;
23//!     Item::new("an-id").validate_blocking().unwrap();
24//! }
25//! ```
26//!
27//! All fetched schemas are cached, so if you're you're doing multiple
28//! validations, you should re-use the same [Validator]:
29//!
30//! ```
31//! # use stac::Item;
32//! # use stac_validate::Validator;
33//! let mut items: Vec<_> = (0..10).map(|n| Item::new(format!("item-{}", n))).collect();
34//! # tokio_test::block_on(async {
35//! let mut validator = Validator::new().await;
36//! for item in items {
37//!     validator.validate(&item).await.unwrap();
38//! }
39//! # })
40//! ```
41//!
42//! [Validator] is cheap to clone, so you are encouraged to validate a large
43//! number of objects at the same time if that's your use-case.
44
45#![deny(
46    elided_lifetimes_in_paths,
47    explicit_outlives_requirements,
48    keyword_idents,
49    macro_use_extern_crate,
50    meta_variable_misuse,
51    missing_abi,
52    missing_debug_implementations,
53    missing_docs,
54    non_ascii_idents,
55    noop_method_call,
56    rust_2021_incompatible_closure_captures,
57    rust_2021_incompatible_or_patterns,
58    rust_2021_prefixes_incompatible_syntax,
59    rust_2021_prelude_collisions,
60    single_use_lifetimes,
61    trivial_casts,
62    trivial_numeric_casts,
63    unreachable_pub,
64    unsafe_code,
65    unsafe_op_in_unsafe_fn,
66    unused_crate_dependencies,
67    unused_extern_crates,
68    unused_import_braces,
69    unused_lifetimes,
70    unused_qualifications,
71    unused_results
72)]
73
74#[cfg(feature = "blocking")]
75mod blocking;
76mod error;
77mod validate;
78mod validator;
79
80#[cfg(feature = "blocking")]
81pub use blocking::ValidateBlocking;
82pub use {error::Error, validate::Validate, validator::Validator};
83
84/// Crate-specific result type.
85pub type Result<T> = std::result::Result<T, Error>;
86
87#[cfg(test)]
88use {geojson as _, rstest as _, tokio_test as _};
89
90// From https://github.com/rust-lang/cargo/issues/383#issuecomment-720873790,
91// may they be forever blessed.
92#[cfg(doctest)]
93mod readme {
94    macro_rules! external_doc_test {
95        ($x:expr) => {
96            #[doc = $x]
97            extern "C" {}
98        };
99    }
100
101    external_doc_test!(include_str!("../README.md"));
102}