Skip to main content

StrExt

Trait StrExt 

Source
pub trait StrExt {
    // Required methods
    fn is_blank(&self) -> bool;
    fn to_camel(&self) -> String;
    fn to_snake(&self) -> String;
    fn truncate(&self, max: usize) -> String;
    fn random(len: usize) -> String;

    // Provided method
    fn has_text(&self) -> bool { ... }
}
Expand description

字符串扩展 trait(为 &str 添加实用方法)

导入后可对任何字符串切片调用驼峰/蛇形互转、截断、判空、随机串等方法。

Required Methods§

Source

fn is_blank(&self) -> bool

是否为空白(仅含空格/制表符/换行符)

Source

fn to_camel(&self) -> String

蛇形命名 → 驼峰命名(如 user_nameuserName

Source

fn to_snake(&self) -> String

驼峰命名 → 蛇形命名(如 UserNameuser_name

Source

fn truncate(&self, max: usize) -> String

按字符数截断(超出末尾补 ...

Source

fn random(len: usize) -> String

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

Provided Methods§

Source

fn has_text(&self) -> bool

非空白字符(is_blank 的取反)

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl StrExt for str

Implementors§