77//! ```
88//! use stac::{Item, Validate};
99//!
10- //! # tokio_test::block_on(async {
11- //! Item::new("an-id").validate().await.unwrap();
12- //! # })
13- //! ```
14- //!
15- //! If you're working in a blocking context (not async), enable the `blocking` feature and use [ValidateBlocking]:
16- //!
17- //! ```
18- //! #[cfg(feature = "blocking")]
19- //! {
20- //! use stac::{ValidateBlocking, Item};
21- //! Item::new("an-id").validate_blocking().unwrap();
22- //! }
10+ //! Item::new("an-id").validate().unwrap();
2311//! ```
2412//!
2513//! All fetched schemas are cached, so if you're you're doing multiple
2816//! ```
2917//! # use stac::{Item, Validator};
3018//! let mut items: Vec<_> = (0..10).map(|n| Item::new(format!("item-{}", n))).collect();
31- //! # tokio_test::block_on(async {
32- //! let mut validator = Validator::new().await.unwrap();
19+ //! let mut validator = Validator::new().unwrap();
3320//! for item in items {
34- //! validator.validate(&item).await. unwrap();
21+ //! validator.validate(&item).unwrap();
3522//! }
36- //! # })
3723//! ```
3824//!
3925//! [Validator] is cheap to clone, so you are encouraged to validate a large
4026//! number of objects at the same time if that's your use-case.
4127
4228use crate :: Result ;
4329use serde:: Serialize ;
44- use std:: future:: Future ;
4530
46- #[ cfg( feature = "validate-blocking" ) ]
47- mod blocking;
4831mod validator;
4932
50- #[ cfg( feature = "validate-blocking" ) ]
51- pub use blocking:: ValidateBlocking ;
5233pub use validator:: Validator ;
5334
5435/// Validate any serializable object with [json-schema](https://json-schema.org/)
@@ -68,15 +49,11 @@ pub trait Validate: Serialize + Sized {
6849 /// use stac::{Item, Validate};
6950 ///
7051 /// let mut item = Item::new("an-id");
71- /// # tokio_test::block_on(async {
72- /// item.validate().await.unwrap();
73- /// });
52+ /// item.validate().unwrap();
7453 /// ```
75- fn validate ( & self ) -> impl Future < Output = Result < ( ) > > {
76- async {
77- let validator = Validator :: new ( ) . await ?;
78- validator. validate ( self ) . await
79- }
54+ fn validate ( & self ) -> Result < ( ) > {
55+ let mut validator = Validator :: new ( ) ?;
56+ validator. validate ( self )
8057 }
8158}
8259
0 commit comments