Validates a bounded portable record identifier.
(kind: &str, value: &str)
| 621 | |
| 622 | /// Validates a bounded portable record identifier. |
| 623 | pub fn valid_id(kind: &str, value: &str) -> Result<()> { |
| 624 | if value.is_empty() |
| 625 | || value.len() > 200 |
| 626 | || !value.bytes().all(|b| b.is_ascii_alphanumeric() || matches!(b, b'-' | b'_' | b'.')) |
| 627 | { |
| 628 | bail!("invalid {kind} id {value:?}"); |
| 629 | } |
| 630 | Ok(()) |
| 631 | } |
| 632 | |
| 633 | /// Rejects a string exceeding its byte budget. |
| 634 | pub fn bounded(name: &str, value: &str, maximum: usize) -> Result<()> { |