1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//! This crate contains (de-)serialization modules that can be
//! used for string items with [serde](https://serde.rs/). The
//! (de-)serialization will fail if the required pattern is not matched.
//! This behavior is achieved by matching against a regular expression
//! which defines the allowed pattern.
//!
//! The modules in this crate can be used by the `with` attribute of serde,
//! attached to String elements.
//! ```
//! #[macro_use]
//! extern crate serde_derive;
//!
//! extern crate ommui_string_patterns;
//! extern crate serde_json;
//!
//! use ommui_string_patterns::idstring_maybe_empty;
//!
//! #[derive(Serialize, Deserialize, Debug)]
//! pub struct MyStruct {
//! #[serde(with="idstring_maybe_empty")]
//! pub identifier: String,
//! }
//!
//! fn main() {
//! let json_string = r#"{ "identifier": "hello_world" }"#;
//! let s: MyStruct = serde_json::from_str(json_string).unwrap();
//! println!("Deserialized: {:?}", s);
//! }
//! ```
extern crate lazy_static;
extern crate regex;
extern crate serde;