slugrs 0.5.0

A fast, locale-aware slugify library for Rust
Documentation
use regex::Regex;

/// Configurable options for slugification.
#[derive(Debug, Clone)]
pub struct Options {
    /// Word separator to use in the final slug.
    pub separator: String,
    /// Optional locale mapping for language-specific transliteration rules.
    pub locale: Option<crate::Locale>,
    /// Optional regex to remove characters before processing.
    pub remove: Option<Regex>,
    /// Convert the result to lowercase (default: true)
    pub lowercase: bool,
    /// Trim leading/trailing separators (default: true)
    pub trim: bool,
    /// Maximum length of the slug in characters (None = unlimited)
    pub max_length: Option<usize>,
    /// Drop emoji and symbol characters before processing (default: true)
    pub drop_emoji: bool,
    /// Drop apostrophes before processing (default: true)
    pub drop_apostrophes: bool,
}

impl Default for Options {
    fn default() -> Self {
        Self {
            separator: "-".into(),
            locale: None,
            remove: None,
            lowercase: true,
            trim: true,
            max_length: None,
            drop_emoji: true,
            drop_apostrophes: true,
        }
    }
}

impl Options {
    pub fn separator(mut self, separator: impl Into<String>) -> Self {
        self.separator = separator.into();
        self
    }

    pub fn locale(mut self, locale: Option<crate::Locale>) -> Self {
        self.locale = locale;
        self
    }

    pub fn remove(mut self, remove: Option<Regex>) -> Self {
        self.remove = remove;
        self
    }

    pub fn lowercase(mut self, lowercase: bool) -> Self {
        self.lowercase = lowercase;
        self
    }

    pub fn trim(mut self, trim: bool) -> Self {
        self.trim = trim;
        self
    }

    pub fn max_length(mut self, max_length: Option<usize>) -> Self {
        self.max_length = max_length;
        self
    }

    pub fn drop_emoji(mut self, drop_emoji: bool) -> Self {
        self.drop_emoji = drop_emoji;
        self
    }

    pub fn drop_apostrophes(mut self, drop_apostrophes: bool) -> Self {
        self.drop_apostrophes = drop_apostrophes;
        self
    }
}