Skip to main content

kernel/common/
sink_name.rs

1use nutype::nutype;
2
3#[nutype(
4    sanitize(trim, lowercase),
5    validate(len_char_max = 63, regex = r"^[a-z_][a-z0-9_]*$"),
6    derive(
7        Debug,
8        Clone,
9        Display,
10        AsRef,
11        Deref,
12        Hash,
13        Eq,
14        PartialEq,
15        Ord,
16        PartialOrd,
17        Serialize,
18        Deserialize
19    )
20)]
21pub struct SinkName(String);
22
23/// The identifier grammar the newtype validates, for the editor schema (nutype
24/// has no schemars support, so this mirrors its `validate` attributes).
25impl schemars::JsonSchema for SinkName {
26    fn schema_name() -> std::borrow::Cow<'static, str> {
27        std::borrow::Cow::Borrowed("SinkName")
28    }
29
30    fn json_schema(_: &mut schemars::SchemaGenerator) -> schemars::Schema {
31        schemars::json_schema!({
32            "type": "string",
33            "pattern": "^[a-z_][a-z0-9_]*$",
34            "maxLength": 63,
35            "description": "A sink name: lowercase letters, digits, and underscores, not starting with a digit, at most 63 characters."
36        })
37    }
38}