Skip to main content

Str

Trait Str 

Source
pub trait Str:
    Deref<Target = str>
    + Display
    + Debug
    + Send
    + Sync {
    // Required methods
    fn as_str(&self) -> &str;
    fn dyn_clone(&self) -> Box<dyn Str>;

    // Provided methods
    fn as_bytes(&self) -> &[u8] ⓘ { ... }
    fn len(&self) -> usize { ... }
    fn is_empty(&self) -> bool { ... }
}
Available on crate features types-str and types only.
Expand description

安全字符串的统一接口:只读视图,内部恒为合法 UTF-8。

§Feature Requirement

需要启用 "types-str" 特性。

§Examples

use core::convert::TryInto;
use lib_unknown::types::str::{StackStr, Str};

let s: StackStr<8> = "hi".try_into().unwrap();
assert_eq!(s.as_str(), "hi");
assert_eq!(s.len(), 2);

Required Methods§

Source

fn as_str(&self) -> &str

以 &str 形式查看内容。

§Feature Requirement

需要启用 "types-str" 特性。

Source

fn dyn_clone(&self) -> Box<dyn Str>

Available on crate feature alloc only.

类型擦除的堆克隆,用于 Box<dyn Str> 容器。

§Feature Requirement

需要启用 "types-str" 与 "alloc" 特性。

Provided Methods§

Source

fn as_bytes(&self) -> &[u8] ⓘ

以字节切片查看内容。

§Feature Requirement

需要启用 "types-str" 特性。

Source

fn len(&self) -> usize

返回内容的字节长度。

§Feature Requirement

需要启用 "types-str" 特性。

Source

fn is_empty(&self) -> bool

内容是否为空。

§Feature Requirement

需要启用 "types-str" 特性。

Trait Implementations§

Source§

impl Clone for Box<dyn Str>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Eq for Box<dyn Str>

Source§

impl PartialEq for Box<dyn Str>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<&str> for Box<dyn Str>

Source§

fn eq(&self, other: &&str) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<String> for Box<dyn Str>

Source§

fn eq(&self, other: &String) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<str> for Box<dyn Str>

Source§

fn eq(&self, other: &str) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<const N: usize> Str for HeapStr<N>

Source§

impl<const N: usize> Str for StackStr<N>