Skip to main content

String

Struct String 

Source
pub struct String<'a> {
    pub ch: &'a [char],
    pub len: usize,
}
Expand description

自定义字符串结构体,基于字符切片实现

§示例

use data_structure::linear::string::String;
let chars = ['H', 'e', 'l', 'l', 'o'];
let s = String::new(&chars);

Fields§

§ch: &'a [char]

字符切片

§len: usize

字符串长度

Implementations§

Source§

impl<'a> String<'a>

Source

pub fn new(ch: &'a [char]) -> String<'a>

创建一个新的字符串实例

§参数
  • ch: 字符切片
§返回值

返回新的String实例

§示例
use data_structure::linear::string::String;
let s = String::new(&['R', 'u', 's', 't']);
Source

pub fn index_BF(&self, other: &String<'_>, pos: usize) -> usize

BF算法实现字符串匹配

§参数
  • other: 要匹配的子串
  • pos: 开始匹配的位置
§返回值

返回匹配位置的索引,如果未找到返回0

§示例
use data_structure::linear::string::String;
let s = String::new(&['a','b','c','d','e']);
let sub = String::new(&['c','d']);
assert_eq!(s.index_BF(&sub, 0), 2);

Trait Implementations§

Source§

impl<'a> Clone for String<'a>

Source§

fn clone(&self) -> String<'a>

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

Auto Trait Implementations§

§

impl<'a> Freeze for String<'a>

§

impl<'a> RefUnwindSafe for String<'a>

§

impl<'a> Send for String<'a>

§

impl<'a> Sync for String<'a>

§

impl<'a> Unpin for String<'a>

§

impl<'a> UnsafeUnpin for String<'a>

§

impl<'a> UnwindSafe for String<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.