Expand description
Validated Slug newtype for URL-friendly identifiers.
A Slug is a lowercase ASCII string used as a human-readable URL segment.
It enforces the following constraints at construction time:
- Only lowercase ASCII letters (
a-z), digits (0-9), and hyphens (-) - Length: 1–128 characters
- No leading, trailing, or consecutive hyphens
§Example
use api_bones::slug::{Slug, SlugError};
let slug = Slug::new("hello-world").unwrap();
assert_eq!(slug.as_str(), "hello-world");
let auto = Slug::from_title("Hello, World! 2024");
assert_eq!(auto.as_str(), "hello-world-2024");
assert!(matches!(Slug::new("Hello"), Err(SlugError::InvalidChars)));
assert!(matches!(Slug::new("-bad"), Err(SlugError::LeadingHyphen)));
assert!(matches!(Slug::new(""), Err(SlugError::Empty)));Structs§
- Slug
- A validated, URL-friendly identifier.