threaded/
threaded.rs

1use jsonschema_valid::{schemas, Config};
2use lazy_static::lazy_static;
3use serde_json::Value;
4
5lazy_static! {
6    // Create the schema and schema validator globally once, then re-use them in multiple threads
7    // without problems.
8
9    static ref SCHEMA: Value = serde_json::from_str("{}").unwrap();
10    static ref SCHEMA_CFG: Config<'static> = Config::from_schema(&SCHEMA, Some(schemas::Draft::Draft6)).unwrap();
11}
12
13fn main() {
14    {
15        let data = serde_json::from_str("{}").unwrap();
16        assert!(SCHEMA_CFG.validate(&data).is_ok());
17    }
18
19    std::thread::spawn(|| {
20        let data = serde_json::from_str("{}").unwrap();
21        assert!(SCHEMA_CFG.validate(&data).is_ok());
22    });
23}