Skip to content

slugify

Converts s into a lowercase, hyphen-separated slug safe for URLs.

Letters and digits (Unicode included) are kept and lowercased, apostrophes are dropped, and every other run of characters becomes a single hyphen; leading and trailing hyphens are never produced. Diacritics are not stripped: "café" stays "café".

use helpers4::string::slugify;

Cargo feature string (enabled by default). To compile only this module:

cargo add helpers4 --no-default-features --features string

or in Cargo.toml:

[dependencies]
helpers4 = { version = "0.0.5", default-features = false, features = ["string"] }
pub fn slugify(s: &str) -> String
ParameterTypeDescription
s&strThe text to convert.

String

use helpers4::string::slugify;

assert_eq!(slugify("Hello World!"), "hello-world");
assert_eq!(slugify("  It's  a --- test "), "its-a-test");
assert_eq!(slugify("!!!"), "");

src/string/slugify.rs