Struct StrSlug

Source
pub struct StrSlug {
    pub use_hash: bool,
    pub append_hash: bool,
    pub hash_len: usize,
    pub hash_separator: char,
    pub separator: char,
    pub remove_duplicate_separators: bool,
    pub trim_separator: bool,
    pub trim_separator_start: bool,
    pub trim_separator_end: bool,
}

Fields§

§use_hash: bool§append_hash: bool

if its set to false the hash will be prepended

§hash_len: usize

use full hash if hash_len = 0

§hash_separator: char

separator to use to separate slug and hash

§separator: char§remove_duplicate_separators: bool§trim_separator: bool

Trim leading and trailing separators after slugifying the given string.

§trim_separator_start: bool§trim_separator_end: bool

Implementations§

Source§

impl StrSlug

Source

pub fn new() -> Self

Source

pub fn slug<T: AsRef<str>>(&self, value: T) -> String

Generate a slug for the given value by applying user options.

§Examples

Normal usage

use str_slug::StrSlug;

let str_slug = StrSlug::new();
let slug = str_slug::slug("Hello, World!");
assert_eq!(slug, "hello-world");

Hashed slug

use str_slug::StrSlug;

let mut str_slug = StrSlug::new();
str_slug.use_hash = true;

let slug = str_slug.slug("Hello, World!");
assert_eq!(slug, "hello-world_288a86");

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.