#identifier

ommui_string_patterns

String pattern checkers for OMMUI identifiers

3 releases

Uses old Rust 2015

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

#173 in #identifier

Download history 17/week @ 2024-07-22 28/week @ 2024-07-29 22/week @ 2024-08-05 27/week @ 2024-08-12 19/week @ 2024-08-19 48/week @ 2024-08-26 10/week @ 2024-09-02 26/week @ 2024-09-09 18/week @ 2024-09-16 46/week @ 2024-09-23 15/week @ 2024-09-30 8/week @ 2024-10-07 14/week @ 2024-10-14 15/week @ 2024-10-21 12/week @ 2024-10-28 27/week @ 2024-11-04

68 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.2–3.5MB
~61K SLoC