Skip to main content

Str

Struct Str 

Source
pub struct Str;

Implementations§

Source§

impl Str

Source

pub fn after(subject: &str, search: &str) -> String

Return the remainder of a string after the first occurrence of a given value

Source

pub fn after_last(subject: &str, search: &str) -> String

Return the remainder of a string after the last occurrence of a given value

Source

pub fn ascii(value: &str) -> String

Transliterate a UTF-8 value to ASCII

Source

pub fn transliterate( string: &str, unknown: Option<&str>, strict: Option<bool>, ) -> String

Transliterate a string to its closest ASCII representation

Source

pub fn before(subject: &str, search: &str) -> String

Get the portion of a string before the first occurrence of a given value

Source

pub fn before_last(subject: &str, search: &str) -> String

Get the portion of a string before the last occurrence of a given value

Source

pub fn between(subject: &str, from: &str, to: &str) -> String

Get the portion of a string between two given values

Source

pub fn between_first(subject: &str, from: &str, to: &str) -> String

Get the smallest possible portion of a string between two given values

Source

pub fn camel(value: &str) -> String

Convert a value to camel case

Source

pub fn char_at(subject: &str, index: isize) -> Option<char>

Get the character at the specified index

Source

pub fn chop_start(subject: &str, needles: &[&str]) -> String

Remove the given string(s) if it exists at the start of the haystack

Source

pub fn chop_end(subject: &str, needles: &[&str]) -> String

Remove the given string(s) if it exists at the end of the haystack

Source

pub fn contains(haystack: &str, needles: &[&str], ignore_case: bool) -> bool

Determine if a given string contains a given substring

Source

pub fn contains_all(haystack: &str, needles: &[&str], ignore_case: bool) -> bool

Determine if a given string contains all array values

Source

pub fn doesnt_contain( haystack: &str, needles: &[&str], ignore_case: bool, ) -> bool

Determine if a given string doesn’t contain a given substring

Source

pub fn convert_case(string: &str, mode: CaseMode) -> String

Convert the case of a string

Source

pub fn deduplicate(string: &str, characters: &[char]) -> String

Replace consecutive instances of a given character with a single character

Source

pub fn ends_with(haystack: &str, needles: &[&str]) -> bool

Determine if a given string ends with a given substring

Source

pub fn doesnt_end_with(haystack: &str, needles: &[&str]) -> bool

Determine if a given string doesn’t end with a given substring

Source

pub fn excerpt( text: &str, phrase: &str, options: ExcerptOptions, ) -> Option<String>

Extracts an excerpt from text that matches the first instance of a phrase

Source

pub fn finish(value: &str, cap: &str) -> String

Cap a string with a single instance of a given value

Source

pub fn wrap(value: &str, before: &str, after: Option<&str>) -> String

Wrap the string with the given strings

Source

pub fn unwrap(value: &str, before: &str, after: Option<&str>) -> String

Unwrap the string with the given strings

Source

pub fn is_pattern(patterns: &[&str], value: &str, ignore_case: bool) -> bool

Determine if a given string matches a given pattern (with wildcards)

Source

pub fn is_ascii(value: &str) -> bool

Determine if a given string is 7 bit ASCII

Source

pub fn is_json(value: &str) -> bool

Determine if a given value is valid JSON

Source

pub fn is_url(value: &str, protocols: Option<&[&str]>) -> bool

Determine if a given value is a valid URL

Source

pub fn is_uuid(value: &str, version: Option<UuidVersion>) -> bool

Determine if a given value is a valid UUID

Source

pub fn is_ulid(value: &str) -> bool

Determine if a given value is a valid ULID

Source

pub fn kebab(value: &str) -> String

Convert a string to kebab case

Source

pub fn length(value: &str) -> usize

Return the length of the given string

Source

pub fn limit( value: &str, limit: usize, end: &str, preserve_words: bool, ) -> String

Limit the number of characters in a string

Source

pub fn lower(value: &str) -> String

Convert the given string to lower-case

Source

pub fn words(value: &str, words: usize, end: &str) -> String

Limit the number of words in a string

Source

pub fn markdown(string: &str, options: MarkdownOptions) -> String

Converts GitHub flavored Markdown into HTML

Source

pub fn inline_markdown(string: &str, options: MarkdownOptions) -> String

Converts inline Markdown into HTML

Source

pub fn mask( string: &str, character: char, index: isize, length: Option<usize>, ) -> String

Masks a portion of a string with a repeated character

Source

pub fn match_pattern(pattern: &str, subject: &str) -> String

Get the string matching the given pattern

Source

pub fn is_match(patterns: &[&str], value: &str) -> bool

Determine if a given string matches a given pattern

Source

pub fn match_all(pattern: &str, subject: &str) -> Vec<String>

Get all strings matching the given pattern

Source

pub fn numbers(value: &str) -> String

Remove all non-numeric characters from a string

Source

pub fn pad_both(value: &str, length: usize, pad: &str) -> String

Pad both sides of a string with another

Source

pub fn pad_left(value: &str, length: usize, pad: &str) -> String

Pad the left side of a string with another

Source

pub fn pad_right(value: &str, length: usize, pad: &str) -> String

Pad the right side of a string with another

Source

pub fn parse_callback( callback: &str, default: Option<&str>, ) -> (String, Option<String>)

Parse a Class[@]method style callback into class and method

Source

pub fn plural(value: &str, count: i32, prepend_count: bool) -> String

Get the plural form of an English word

Source

pub fn plural_studly(value: &str, count: i32) -> String

Pluralize the last word of an English, studly caps case string

Source

pub fn plural_pascal(value: &str, count: i32) -> String

Pluralize the last word of an English, Pascal caps case string

Source

pub fn password( length: usize, letters: bool, numbers: bool, symbols: bool, spaces: bool, ) -> String

Generate a random, secure password

Source

pub fn position(haystack: &str, needle: &str, offset: usize) -> Option<usize>

Find the multi-byte safe position of the first occurrence of a given substring

Source

pub fn random(length: usize) -> String

Generate a more truly “random” alpha-numeric string

Source

pub fn create_random_strings_using<F>(factory: F)
where F: Fn(usize) -> String + Send + Sync + 'static,

Set the callable that will be used to generate random strings

Source

pub fn create_random_strings_using_sequence(sequence: Vec<String>)

Set the sequence that will be used to generate random strings

Source

pub fn create_random_strings_normally()

Indicate that random strings should be created normally

Source

pub fn repeat(string: &str, times: usize) -> String

Repeat the given string

Source

pub fn replace_array(search: &str, replace: &[&str], subject: &str) -> String

Replace a given value in the string sequentially with an array

Source

pub fn replace( search: &[&str], replace: &[&str], subject: &str, case_sensitive: bool, ) -> String

Replace the given value in the given string

Source

pub fn replace_first(search: &str, replace: &str, subject: &str) -> String

Replace the first occurrence of a given value in the string

Source

pub fn replace_start(search: &str, replace: &str, subject: &str) -> String

Replace the first occurrence of the given value if it appears at the start

Source

pub fn replace_last(search: &str, replace: &str, subject: &str) -> String

Replace the last occurrence of a given value in the string

Source

pub fn replace_end(search: &str, replace: &str, subject: &str) -> String

Replace the last occurrence of a given value if it appears at the end

Source

pub fn replace_matches( pattern: &str, replace: &str, subject: &str, limit: Option<usize>, ) -> String

Replace the patterns matching the given regular expression

Source

pub fn remove(search: &[&str], subject: &str, case_sensitive: bool) -> String

Remove any occurrence of the given string in the subject

Source

pub fn reverse(value: &str) -> String

Reverse the given string

Source

pub fn start(value: &str, prefix: &str) -> String

Begin a string with a single instance of a given value

Source

pub fn upper(value: &str) -> String

Convert the given string to upper-case

Source

pub fn title(value: &str) -> String

Convert the given string to title case

Source

pub fn headline(value: &str) -> String

Convert the given string to headline case

Source

pub fn apa(value: &str) -> String

Convert the given string to APA-style title case

Source

pub fn singular(value: &str) -> String

Get the singular form of an English word

Source

pub fn slug( title: &str, separator: &str, language: Option<&str>, dictionary: Option<HashMap<String, String>>, ) -> String

Generate a URL friendly “slug” from a given string

Source

pub fn snake(value: &str, delimiter: &str) -> String

Convert a string to snake case

Source

pub fn trim(value: &str) -> String

Remove all whitespace from both ends of a string

Source

pub fn trim_custom(value: &str, charlist: Option<&str>) -> String

Remove all whitespace from both ends of a string with custom character list

Source

pub fn ltrim(value: &str, charlist: Option<&str>) -> String

Remove all whitespace from the beginning of a string

Source

pub fn rtrim(value: &str, charlist: Option<&str>) -> String

Remove all whitespace from the end of a string

Source

pub fn squish(value: &str) -> String

Remove all “extra” blank space from the given string

Source

pub fn starts_with(haystack: &str, needles: &[&str]) -> bool

Determine if a given string starts with a given substring

Source

pub fn doesnt_start_with(haystack: &str, needles: &[&str]) -> bool

Determine if a given string doesn’t start with a given substring

Source

pub fn studly(value: &str) -> String

Convert a value to studly caps case

Source

pub fn pascal(value: &str) -> String

Convert a value to Pascal case (alias for studly)

Source

pub fn substr(string: &str, start: isize, length: Option<usize>) -> String

Returns the portion of the string specified by the start and length parameters

Source

pub fn substr_count( haystack: &str, needle: &str, offset: usize, length: Option<usize>, ) -> usize

Returns the number of substring occurrences

Source

pub fn substr_replace( string: &str, replace: &str, offset: isize, length: Option<usize>, ) -> String

Replace text within a portion of a string

Source

pub fn swap(map: HashMap<String, String>, subject: &str) -> String

Swap multiple keywords in a string with other keywords

Source

pub fn take(string: &str, limit: isize) -> String

Take the first or last {$limit} characters of a string

Source

pub fn to_base64(string: &str) -> String

Convert the given string to Base64 encoding

Source

pub fn from_base64(string: &str, strict: bool) -> Result<String, DecodeError>

Decode the given Base64 encoded string

Source

pub fn lcfirst(string: &str) -> String

Make a string’s first character lowercase

Source

pub fn ucfirst(string: &str) -> String

Make a string’s first character uppercase

Source

pub fn uc_split(string: &str) -> Vec<String>

Split a string into pieces by uppercase characters

Source

pub fn word_count(string: &str, characters: Option<&str>) -> usize

Get the number of words a string contains

Source

pub fn word_wrap( string: &str, characters: usize, break_str: &str, cut_long_words: bool, ) -> String

Wrap a string to a given number of characters

Source

pub fn uuid() -> Uuid

Generate a UUID (version 4)

Source

pub fn uuid7(time: Option<DateTime<Utc>>) -> Uuid

Generate a UUID (version 7)

Source

pub fn ordered_uuid() -> Uuid

Generate a time-ordered UUID

Source

pub fn create_uuids_using<F>(factory: F)
where F: Fn() -> Uuid + Send + Sync + 'static,

Set the callable that will be used to generate UUIDs

Source

pub fn create_uuids_using_sequence(sequence: Vec<Uuid>)

Set the sequence that will be used to generate UUIDs

Source

pub fn freeze_uuids<F>(callback: Option<F>) -> Uuid
where F: FnOnce(Uuid),

Always return the same UUID when generating new UUIDs

Source

pub fn create_uuids_normally()

Indicate that UUIDs should be created normally and not using a custom factory

Source

pub fn ulid(time: Option<DateTime<Utc>>) -> Ulid

Generate a ULID

Source

pub fn create_ulids_normally()

Indicate that ULIDs should be created normally and not using a custom factory

Source

pub fn create_ulids_using<F>(factory: F)
where F: Fn() -> Ulid + Send + Sync + 'static,

Set the callable that will be used to generate ULIDs

Source

pub fn create_ulids_using_sequence(sequence: Vec<Ulid>)

Set the sequence that will be used to generate ULIDs

Source

pub fn freeze_ulids<F>(callback: Option<F>) -> Ulid
where F: FnOnce(Ulid),

Always return the same ULID when generating new ULIDs

Source

pub fn flush_cache()

Remove all strings from the casing caches

Auto Trait Implementations§

§

impl Freeze for Str

§

impl RefUnwindSafe for Str

§

impl Send for Str

§

impl Sync for Str

§

impl Unpin for Str

§

impl UnsafeUnpin for Str

§

impl UnwindSafe for Str

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> ErasedDestructor for T
where T: 'static,

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V