3 releases

Uses old Rust 2015

0.1.2 May 2, 2018
0.1.1 Apr 25, 2018
0.1.0 Apr 25, 2018

#1775 in Encoding

Download history 121/week @ 2024-04-01 29/week @ 2024-04-08 27/week @ 2024-04-15 25/week @ 2024-04-22 23/week @ 2024-04-29 27/week @ 2024-05-06 36/week @ 2024-05-13 27/week @ 2024-05-20 29/week @ 2024-05-27 27/week @ 2024-06-03 33/week @ 2024-06-10 24/week @ 2024-06-17 34/week @ 2024-06-24 10/week @ 2024-07-08 43/week @ 2024-07-15

88 downloads per month
Used in 12 crates (4 directly)

AGPL-3.0

15KB
201 lines

This crate contains (de-)serialization modules that can be used for string items with serde. 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);
}

Dependencies

~2.3–3.5MB
~61K SLoC