Skip to main content

protovalidate_buffa/
rules.rs

1pub mod string {
2    /// Canonical hyphenated UUID per RFC 4122 §3.
3    ///
4    /// Accepts the 36-character `8-4-4-4-12` hex form only; the `uuid`
5    /// crate's `try_parse` also accepts simple (32-char), URN, and brace
6    /// forms, which protovalidate's `string.uuid` rule rejects.
7    // `const fn` is not possible here because `uuid::Uuid::try_parse` isn't
8    // const. `Clippy::missing_const_for_fn` flags it anyway; silence the false
9    // positive rather than refactor around an upstream limitation.
10    #[allow(clippy::missing_const_for_fn)]
11    #[must_use]
12    pub fn is_uuid(s: &str) -> bool {
13        s.len() == 36 && ::uuid::Uuid::try_parse(s).is_ok()
14    }
15}
16
17pub mod float {
18    #[must_use]
19    pub const fn is_finite_f32(f: f32) -> bool {
20        f.is_finite()
21    }
22    #[must_use]
23    pub const fn is_finite_f64(f: f64) -> bool {
24        f.is_finite()
25    }
26}