home ~ projects ~ socials

Create Text Slugs In Rust

The slug crate is great for making urls and filenames from strings of text. For example:

use slug::slugify;

fn main() {
    let text = "This is.!~ the test   ";
    let slug = slugify(text);
    println!("{}", slug);
}
Output:
this-is-the-test

Notes

  • Add the create with cargo add slug
  • Returns a-z, 0-9, and '-'
  • never contain more than one '-'
  • never start or end with '-'
-- end of line --

References