StringUtil

Struct StringUtil 

Source
pub struct StringUtil;
Expand description

StringUtil 是一个工具结构体,用于处理字符串相关的操作。

Implementations§

Source§

impl StringUtil

Source

pub const EMPTY: &'static str = ""

空字符串。

Source

pub fn generate_random_string(length: usize) -> String

生成指定长度的随机字母数字字符串

Source

pub fn is_blank(s: &str) -> bool

检查字符串是否为空或仅包含空白字符。

§参数
  • s: 待检查的字符串。
§返回值

如果字符串为空或仅包含空白字符,则返回 true;否则返回 false

Source

pub fn is_not_blank(s: &str) -> bool

检查字符串是否非空且不全是空白字符。

§参数
  • s: 待检查的字符串。
§返回值

如果字符串非空且不全是空白字符,则返回 true;否则返回 false

Source

pub fn is_numeric(s: &str) -> bool

检查字符串是否仅包含数字字符。

§参数
  • s: 待检查的字符串。
§返回值

如果字符串仅包含数字字符,则返回 true;否则返回 false

Source

pub fn is_alpha(s: &str) -> bool

检查字符串是否仅包含字母字符。

§参数
  • s: 待检查的字符串。
§返回值

如果字符串仅包含字母字符,则返回 true;否则返回 false

Source

pub fn is_text(s: &str) -> bool

检查字符串是否为纯文本(仅包含字母数字字符或空白字符)。

§参数
  • s: 待检查的字符串。
§返回值

如果字符串为纯文本,则返回 true;否则返回 false

Source

pub fn url_encode(input: &str) -> String

对字符串进行 URL 编码。

§参数
  • input: 待编码的字符串。
§返回值

返回经过 URL 编码的字符串。

Source

pub fn substring(s: &str, start: usize, end: usize) -> String

截取字符串的一部分。

§参数
  • s: 原始字符串。
  • start: 起始索引(从 0 开始)。
  • end: 结束索引(不包含该位置)。
§返回值

返回截取后的子字符串。如果索引超出范围,则返回空字符串。

Source

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

反转字符串。

§参数
  • s: 原始字符串。
§返回值

返回反转后的字符串。

Source

pub fn to_uppercase(s: &str) -> String

将字符串转换为大写。

§参数
  • s: 原始字符串。
§返回值

返回转换为大写的字符串。

Source

pub fn to_lowercase(s: &str) -> String

将字符串转换为小写。

§参数
  • s: 原始字符串。
§返回值

返回转换为小写的字符串。

Source

pub fn remove_duplicates(s: &str) -> String

去除字符串中的重复字符。

§参数
  • s: 原始字符串。
§返回值

返回去重后的字符串。

Source

pub fn starts_with(s: &str, prefix: &str) -> bool

检查字符串是否以指定前缀开头。

§参数
  • s: 原始字符串。
  • prefix: 待检查的前缀。
§返回值

如果字符串以指定前缀开头,则返回 true;否则返回 false

Source

pub fn ends_with(s: &str, suffix: &str) -> bool

检查字符串是否以指定后缀结尾。

§参数
  • s: 原始字符串。
  • suffix: 待检查的后缀。
§返回值

如果字符串以指定后缀结尾,则返回 true;否则返回 false

Source

pub fn contains_whitespace(s: &str) -> bool

检查字符串是否包含空白字符串。

§参数
  • s: 原始字符串。
§返回值

如果字符串包含空白,则返回 true;否则返回 false

Source

pub fn remove_suffix(s: &str, suffix: &str) -> String

移除字符串中的指定前缀和后缀。

§参数
  • s: 原始字符串。
  • prefix: 待移除的前缀。
  • suffix: 待移除的后缀。
§返回值

返回移除前缀和后缀后的字符串。

Source

pub fn remove_prefix(s: &str, prefix: &str) -> String

移除字符串中的指定前缀。

§参数
  • s: 原始字符串。
  • prefix: 待移除的前缀。
§返回值

返回移除前缀后的字符串。

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<Src, Scheme> ApproxFrom<Src, Scheme> for Src
where Scheme: ApproxScheme,

Source§

type Err = NoError

The error type produced by a failed conversion.
Source§

fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>

Convert the given value into an approximately equivalent representation.
Source§

impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Src
where Dst: ApproxFrom<Src, Scheme>, Scheme: ApproxScheme,

Source§

type Err = <Dst as ApproxFrom<Src, Scheme>>::Err

The error type produced by a failed conversion.
Source§

fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>

Convert the subject into an approximately equivalent representation.
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, Dst> ConvAsUtil<Dst> for T

Source§

fn approx(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst>,

Approximate the subject with the default scheme.
Source§

fn approx_by<Scheme>(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst, Scheme>, Scheme: ApproxScheme,

Approximate the subject with a specific scheme.
Source§

impl<T> ConvUtil for T

Source§

fn approx_as<Dst>(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst>,

Approximate the subject to a given type with the default scheme.
Source§

fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst, Scheme>, Scheme: ApproxScheme,

Approximate the subject to a given type with a specific scheme.
Source§

fn into_as<Dst>(self) -> Dst
where Self: Sized + Into<Dst>,

Convert the subject to a given type.
Source§

fn try_as<Dst>(self) -> Result<Dst, Self::Err>
where Self: Sized + TryInto<Dst>,

Attempt to convert the subject to a given type.
Source§

fn value_as<Dst>(self) -> Result<Dst, Self::Err>
where Self: Sized + ValueInto<Dst>,

Attempt a value conversion of the subject to a given type.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<Src> TryFrom<Src> for Src

Source§

type Err = NoError

The error type produced by a failed conversion.
Source§

fn try_from(src: Src) -> Result<Src, <Src as TryFrom<Src>>::Err>

Convert the given value into the subject type.
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<Src, Dst> TryInto<Dst> for Src
where Dst: TryFrom<Src>,

Source§

type Err = <Dst as TryFrom<Src>>::Err

The error type produced by a failed conversion.
Source§

fn try_into(self) -> Result<Dst, <Src as TryInto<Dst>>::Err>

Convert the subject into the destination type.
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

Source§

impl<Src> ValueFrom<Src> for Src

Source§

type Err = NoError

The error type produced by a failed conversion.
Source§

fn value_from(src: Src) -> Result<Src, <Src as ValueFrom<Src>>::Err>

Convert the given value into an exactly equivalent representation.
Source§

impl<Src, Dst> ValueInto<Dst> for Src
where Dst: ValueFrom<Src>,

Source§

type Err = <Dst as ValueFrom<Src>>::Err

The error type produced by a failed conversion.
Source§

fn value_into(self) -> Result<Dst, <Src as ValueInto<Dst>>::Err>

Convert the subject into an exactly equivalent representation.