A trait that validates schema namespaces. To register a custom one use [`set_schema_namespace_validator`].
| 134 | /// |
| 135 | /// To register a custom one use [`set_schema_namespace_validator`]. |
| 136 | pub trait SchemaNamespaceValidator: Send + Sync { |
| 137 | /// The regex used to validate the schema namespace. |
| 138 | /// |
| 139 | /// The default implementation uses the Avro specified regex. |
| 140 | fn regex(&self) -> &'static Regex { |
| 141 | static NAMESPACE_ONCE: OnceLock<Regex> = OnceLock::new(); |
| 142 | NAMESPACE_ONCE.get_or_init(|| { |
| 143 | Regex::new(r"^([A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)*)?$").unwrap() |
| 144 | }) |
| 145 | } |
| 146 | |
| 147 | /// Validates a schema namespace. |
| 148 | /// |
| 149 | /// Should return [`Details::InvalidNamespace`] if it is invalid. |
| 150 | fn validate(&self, namespace: &str) -> AvroResult<()> { |
| 151 | let regex = SchemaNamespaceValidator::regex(self); |
| 152 | if !regex.is_match(namespace) { |
| 153 | Err(Details::InvalidNamespace(namespace.to_string(), regex.as_str()).into()) |
| 154 | } else { |
| 155 | Ok(()) |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | impl SchemaNamespaceValidator for SpecificationValidator {} |
| 161 |
nothing calls this directly
no outgoing calls
no test coverage detected