Struct StrHelper

Source
pub struct StrHelper { /* private fields */ }
Expand description

Modification of &str / String.

§Example:

#[macro_use] extern crate std_helper;
use std_helper::StrHelper;

let mut helper = StrHelper::new("Hello, Rust!");

let result = helper.remove("Rust").unwrap();
assert_eq!(result, "Hello, !");

helper.push("World");
assert_eq!(helper.as_str(), "Hello, !World");

helper.move_to_the_end((7, 8));
assert_eq!(helper.as_str(), "Hello, World!");

Implementations§

Source§

impl StrHelper

Source

pub fn split_str(&self, separator: &str) -> Vec<Option<&str>>

split self''' at separators and get Vec<Option<&str>>```.

§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;

let helper = str!("hello|g|cc");

let g = helper.split_str("|").get(1).unwrap().clone();
assert_eq!(g.unwrap(), "g");
Source

pub fn split_and_get_str(&self, separator: &str, n: usize) -> Option<&str>

split self''' at separators and get &str’‘’.

§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;

let helper = str!("hello|world|rust");

let part = helper.split_and_get_str("|", 1).unwrap();
assert_eq!(part, "world");
Source

pub fn split_and_get_first_str(&self, separator: &str) -> Option<&str>

split self''' at separators and get first &str’‘’.

§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;

let helper = str!("hello|world|rust");

let part = helper.split_and_get_first_str("|").unwrap();
assert_eq!(part, "hello");
Source

pub fn split_and_get_last_str(&self, separator: &str) -> Option<&str>

split self''' at separators and get last &str’‘’.

§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;

let helper = str!("hello|world|rust");

let part = helper.split_and_get_last_str("|").unwrap();
assert_eq!(part, "rust");
Source

pub fn split_str_on_the_sides(&self, separator: (&str, &str)) -> Option<&str>

split self''' at separators on the sides and get &str```.

§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;

let helper = str!("hello");

let l = helper.split_str_on_the_sides(("e", "lo")).unwrap();
assert_eq!(l, "l");
Source§

impl StrHelper

Source

pub fn split_string(&self, separator: &str) -> Vec<Option<String>>

split self''' at separators and get Vec<Option>```.

§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;

let helper = str!("hello|g|cc");

let g = helper.split_string("|").get(1).unwrap().clone();
assert_eq!(g.unwrap(), "g");
Source

pub fn split_and_get_string(&self, separator: &str, n: usize) -> Option<String>

split self''' at separators and get String’‘’.

§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;

let helper = str!("hello|world|rust");

let part = helper.split_and_get_string("|", 1).unwrap();
assert_eq!(part, "world");
Source

pub fn split_and_get_first_string(&self, separator: &str) -> Option<String>

split self''' at separators and get first String’‘’.

§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;

let helper = str!("hello|world|rust");

let part = helper.split_and_get_first_string("|").unwrap();
assert_eq!(part, "hello");
Source

pub fn split_and_get_last_string(&self, separator: &str) -> Option<String>

split self''' at separators and get last String’‘’.

§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;

let helper = str!("hello|world|rust");

let part = helper.split_and_get_last_string("|").unwrap();
assert_eq!(part, "rust");
Source

pub fn split_string_on_the_sides( &self, separator: (&str, &str), ) -> Option<String>

split self''' at separators on the sides and get String```.

§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;

let helper = str!("hello");

let l = helper.split_string_on_the_sides(("e", "lo")).unwrap();
assert_eq!(l, "l");
Source§

impl StrHelper

Source

pub fn split(&self, separator: &str) -> Vec<Option<StrHelper>>

split self''' at separators and get Vec<Option>```.

§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;

let helper = str!("hello|g|cc");

let g = helper.split("|").get(1).unwrap().clone();
assert_eq!(g.unwrap().as_str(), "g");
Source

pub fn split_and_get(&self, separator: &str, n: usize) -> Option<StrHelper>

split self''' at separators and get StrHelper’‘’.

§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;

let helper = str!("hello|world|rust");

let part = helper.split_and_get("|", 1).unwrap();
assert_eq!(part.as_str(), "world");
Source

pub fn split_and_get_first(&self, separator: &str) -> Option<StrHelper>

split self''' at separators and get first StrHelper’‘’.

§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;

let helper = str!("hello|world|rust");

let part = helper.split_and_get_first("|").unwrap();
assert_eq!(part.as_str(), "hello");
Source

pub fn split_and_get_last(&self, separator: &str) -> Option<StrHelper>

split self''' at separators and get last StrHelper’‘’.

§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;

let helper = str!("hello|world|rust");

let part = helper.split_and_get_last("|").unwrap();
assert_eq!(part.as_str(), "rust");
Source

pub fn split_on_the_sides(&self, separator: (&str, &str)) -> Option<StrHelper>

split self''' at separators on the sides and get StrHelper```.

§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;

let helper = str!("hello");

let l = helper.split_on_the_sides(("e", "lo")).unwrap();
assert_eq!(l.as_str(), "l");
Source§

impl StrHelper

Source

pub fn split_str_at(&self, mid: usize) -> (Option<&str>, Option<&str>)

split self''' at index and get (Option<&str>, Option<&str>)```.

§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;

let helper = str!("Crab is Rust!");

let crab = helper.split_str_at(4).0.unwrap();
assert_eq!(crab, "Crab");
Source

pub fn split_str_on_the_sides_at(&self, mid: (usize, usize)) -> Option<&str>

split self''' at indexes and get &str```.

§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;

let helper = str!("Crab is Rust!");

let is = helper.split_str_on_the_sides_at((5, 7)).unwrap();
assert_eq!(is, "is");
Source§

impl StrHelper

Source

pub fn split_string_at(&self, mid: usize) -> (Option<String>, Option<String>)

split self''' at index and get (Option, Option)```.

§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;

let helper = str!("Crab is Rust!");

let crab = helper.split_string_at(4).0.unwrap();
assert_eq!(crab, "Crab");
Source

pub fn split_string_on_the_sides_at( &self, mid: (usize, usize), ) -> Option<String>

split self''' at indexes and get String```.

§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;

let helper = str!("Crab is Rust!");

let is = helper.split_string_on_the_sides_at((5, 7)).unwrap();
assert_eq!(is, "is");
Source§

impl StrHelper

Source

pub fn split_at(&self, mid: usize) -> (Option<StrHelper>, Option<StrHelper>)

split self''' at index and get (Option, Option)```.

§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;

let helper = str!("Crab is Rust!");

let crab = helper.split_at(4).0.unwrap();
assert_eq!(crab.as_str(), "Crab");
Source

pub fn split_on_the_sides_at(&self, mid: (usize, usize)) -> Option<StrHelper>

split self''' at indexes and get StrHelper```.

§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;

let helper = str!("Crab is Rust!");

let is = helper.split_on_the_sides_at((5, 7)).unwrap();
assert_eq!(is.as_str(), "is");
Source§

impl StrHelper

Source

pub fn generate_string_from_char_vec(vector: Vec<char>) -> String

generate String from Vec<char>

Source

pub fn generate_string_from_chars(values: &[char]) -> String

generate String from &[char]

Source§

impl StrHelper

Source

pub fn to_string(&self) -> String

get ‘’‘String’‘’ version of helper.

Source

pub fn as_str(&self) -> &str

get ‘’‘&str’‘’ version of helper.

Source

pub fn as_chars(&self) -> Vec<char>

get ‘’‘Vec’‘’ version of helper.

Source

pub fn contains(&self, pat: &str) -> bool

get element location status in string.

§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;

let helper = str!("Hi!");
assert_eq!(helper.contains("Hi"), true);
assert_eq!(helper.contains("crab"), false);
Source

pub fn other_as_chars(value: &str) -> Vec<char>

get ‘’‘Vec’‘’ version of other ‘’‘&str’‘’.

Source§

impl StrHelper

Source

pub fn remove(&mut self, p: &str) -> Option<String>

remove part if it contains.

§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;

let mut helper = str!("Hello, F****** ***T *I***, World!");
let result = helper.remove("F****** ***T *I***, ").unwrap();

assert_eq!(result, helper.to_string(), "Hello, World!");
Source

pub fn remove_at(&mut self, p_indexes: (usize, usize)) -> Option<String>

remove part at indexes.

§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;

let mut helper = str!("Hello, @@@World!");
let result = helper.remove_at((7, 10)).unwrap();

assert_eq!(result, helper.to_string(), "Hello, World!");
Source§

impl StrHelper

Source

pub fn insert(&mut self, new_part: &str, index: usize) -> Option<String>

insert element at string.

§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;

let mut helper = str!("Hello!");
let result = helper.insert(", World", 5).unwrap();

assert_eq!(result, "Hello, World!")
Source

pub fn insert_at_the_beginning(&mut self, new_part: &str) -> Option<String>

insert element at the beginning of string.

§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;

let mut helper = str!("World!");
let result = helper.insert_at_the_beginning("Hello, ").unwrap();

assert_eq!(result, "Hello, World!")
Source

pub fn push(&mut self, new_part: &str) -> Option<String>

insert element at the end of string.

§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;

let mut helper = str!("Hello");
let result = helper.push(", World!").unwrap();

assert_eq!(result, "Hello, World!")
Source§

impl StrHelper

Source

pub fn move_to( &mut self, p_indexes: (usize, usize), new_index: usize, ) -> Option<String>

move element to index, using part’s indexes.

§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;

let mut helper = str!("He, lloWorld!");
let result = helper.move_to((4, 7), 2).unwrap();

assert_eq!(result, "Hello, World!");
Source

pub fn move_to_the_beginning( &mut self, p_indexes: (usize, usize), ) -> Option<String>

move element to the beginning, using part’s indexes.

§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;

let mut helper = str!("World!Hello, ");
let result = helper.move_to_the_beginning((6, 13)).unwrap();

assert_eq!(result, "Hello, World!");
Source

pub fn move_to_the_end(&mut self, p_indexes: (usize, usize)) -> Option<String>

move element to the end, using part’s indexes.

§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;

let mut helper = str!("World!Hello, ");
let result = helper.move_to_the_end((0, 6)).unwrap();

assert_eq!(result, "Hello, World!");
Source

pub fn switch_beginning_and_end(&mut self) -> Option<String>

switch first and last chars of string.

§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;

let mut helper = str!("!ello, WorldH");
let _ = helper.switch_beginning_and_end();

assert_eq!(helper.as_str(), "Hello, World!")
Source§

impl StrHelper

Source

pub fn new(value: &str) -> StrHelper

init struct from &str.

§Example:
use std_helper::StrHelper;

let helper = StrHelper::new("Language Crab is Rust...");
assert_eq!(helper.as_str(), "Language Crab is Rust...");
Source

pub fn empty() -> StrHelper

init empty struct.

§Example:
use std_helper::*;

let empty_helper = StrHelper::empty();
assert_eq!(empty_helper.as_str(), "");
assert_eq!(empty_helper, str!());
Source

pub fn from_string(value: String) -> StrHelper

init struct from String.

§Example:
use std_helper::StrHelper;

let helper = StrHelper::from_string(String::new());
assert_eq!(helper.as_str(), "");
Source

pub fn from_chars_vector(vector: Vec<char>) -> StrHelper

init struct from Vec<char>.

§Example:
use std_helper::StrHelper;

let chars = vec!['h', 'p'];
let helper = StrHelper::from_chars_vector(chars);

assert_eq!(helper.as_str(), "hp");
Source

pub fn from_chars(values: &[char]) -> StrHelper

init struct from &[char].

§Example:
use std_helper::StrHelper;

let chars = ['h', 'p'].as_ref();
let helper = StrHelper::from_chars(chars);

assert_eq!(helper.as_str(), "hp");
Source

pub fn update(&mut self, new_value: &str)

change string.

§Example:
use std_helper::StrHelper;

let mut helper = StrHelper::new("Rust");
helper.update("Crab");

assert_eq!(helper.as_str(), "Crab");
Source

pub fn reverse(&mut self)

reverse string.

§Example:
use std_helper::StrHelper;

let mut helper = StrHelper::new("1234567890");
helper.reverse();

assert_eq!(helper.as_str(), "0987654321");

Trait Implementations§

Source§

impl Clone for StrHelper

Source§

fn clone(&self) -> StrHelper

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for StrHelper

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for StrHelper

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for StrHelper

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<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 = 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.