Trait ArrayStringManipulate

Source
pub trait ArrayStringManipulate<N: Alphanumeric>
where Self: Sized + Clone,
{
Show 21 methods // Required methods fn add(&self, other: &Array<N>) -> Result<Array<N>, ArrayError>; fn multiply(&self, counts: &Array<usize>) -> Result<Array<N>, ArrayError>; fn capitalize(&self) -> Result<Array<N>, ArrayError>; fn lower(&self) -> Result<Array<N>, ArrayError>; fn upper(&self) -> Result<Array<N>, ArrayError>; fn swapcase(&self) -> Result<Array<N>, ArrayError>; fn center( &self, width: &Array<usize>, fill_char: Option<Array<char>>, ) -> Result<Array<N>, ArrayError>; fn join(&self, sep: &Array<N>) -> Result<Array<N>, ArrayError>; fn partition( &self, sep: &Array<N>, ) -> Result<Array<Tuple3<N, N, N>>, ArrayError>; fn rpartition( &self, sep: &Array<N>, ) -> Result<Array<Tuple3<N, N, N>>, ArrayError>; fn split( &self, sep: Option<Array<N>>, max_split: Option<Array<usize>>, ) -> Result<Array<List<N>>, ArrayError>; fn rsplit( &self, sep: Option<Array<N>>, max_split: Option<Array<usize>>, ) -> Result<Array<List<N>>, ArrayError>; fn splitlines( &self, keep_ends: Option<Array<bool>>, ) -> Result<Array<List<N>>, ArrayError>; fn replace( &self, old: &Array<N>, new: &Array<N>, count: Option<usize>, ) -> Result<Array<N>, ArrayError>; fn strip(&self, chars: Option<Array<N>>) -> Result<Array<N>, ArrayError>; fn lstrip(&self, chars: Option<Array<N>>) -> Result<Array<N>, ArrayError>; fn rstrip(&self, chars: Option<Array<N>>) -> Result<Array<N>, ArrayError>; fn ljust( &self, width: &Array<usize>, fill_char: Option<Array<char>>, ) -> Result<Array<N>, ArrayError>; fn rjust( &self, width: &Array<usize>, fill_char: Option<Array<char>>, ) -> Result<Array<N>, ArrayError>; fn zfill(&self, width: usize) -> Result<Array<N>, ArrayError>; fn translate( &self, table: Vec<(char, char)>, ) -> Result<Array<N>, ArrayError>;
}
Expand description

ArrayTrait - Alphanumeric Array operations

Required Methods§

Source

fn add(&self, other: &Array<N>) -> Result<Array<N>, ArrayError>

Return element-wise string concatenation for two arrays of String

§Arguments
  • other - array to perform the operation with
§Examples
use arr_rs::prelude::*;

let expected = Array::flat(vec!["abcdd".to_string(), "cdeff".to_string()]);
let arr = Array::flat(vec!["abc".to_string(), "cde".to_string()]);
let other = Array::flat(vec!["dd".to_string(), "ff".to_string()]).unwrap();
assert_eq!(expected, arr.add(&other));
§Errors

may returns ArrayError

Source

fn multiply(&self, counts: &Array<usize>) -> Result<Array<N>, ArrayError>

Return (a * i), that is string multiple concatenation, element-wise

§Arguments
  • counts - array to perform the operation with
§Examples
use arr_rs::prelude::*;

let expected = Array::flat(vec!["aaa".to_string(), "bbbbb".to_string()]);
let arr = Array::flat(vec!["a".to_string(), "b".to_string()]);
let counts = Array::flat(vec![3, 5]).unwrap();
assert_eq!(expected, arr.multiply(&counts));
§Errors

may returns ArrayError

Source

fn capitalize(&self) -> Result<Array<N>, ArrayError>

Capitalizes first character of each element

§Examples
use arr_rs::prelude::*;

let expected = Array::flat(vec!["A1a".to_string(), "2bb".to_string()]);
let arr = Array::flat(vec!["a1a".to_string(), "2bb".to_string()]);
assert_eq!(expected, arr.capitalize());
§Errors

may returns ArrayError

Source

fn lower(&self) -> Result<Array<N>, ArrayError>

Turns characters to lower-case

§Examples
use arr_rs::prelude::*;

let expected = Array::flat(vec!["a1a".to_string(), "2bb".to_string()]);
let arr = Array::flat(vec!["A1a".to_string(), "2bB".to_string()]);
assert_eq!(expected, arr.lower());
§Errors

may returns ArrayError

Source

fn upper(&self) -> Result<Array<N>, ArrayError>

Turns characters to upper-case

§Examples
use arr_rs::prelude::*;

let expected = Array::flat(vec!["A1A".to_string(), "2BB".to_string()]);
let arr = Array::flat(vec!["a1a".to_string(), "2bb".to_string()]);
assert_eq!(expected, arr.upper());
§Errors

may returns ArrayError

Source

fn swapcase(&self) -> Result<Array<N>, ArrayError>

Swap characters case

§Examples
use arr_rs::prelude::*;

let expected = Array::flat(vec!["A1a".to_string(), "2bB".to_string()]);
let arr = Array::flat(vec!["a1A".to_string(), "2Bb".to_string()]);
assert_eq!(expected, arr.swapcase());
§Errors

may returns ArrayError

Source

fn center( &self, width: &Array<usize>, fill_char: Option<Array<char>>, ) -> Result<Array<N>, ArrayError>

Centers elements in a string of length of width

§Arguments
  • width - length of the resulting strings
  • fill_char - padding character to use. defaults to space
§Examples
use arr_rs::prelude::*;

let expected = Array::flat(vec!["***aaa***".to_string(), "***bbbb**".to_string()]);
let arr = Array::flat(vec!["aaa".to_string(), "bbbb".to_string()]);
assert_eq!(expected, arr.center(&Array::single(9).unwrap(), Some(Array::single('*').unwrap())));
§Errors

may returns ArrayError

Source

fn join(&self, sep: &Array<N>) -> Result<Array<N>, ArrayError>

Concatenate the strings in the sequence

§Arguments
  • sep - array of separators to concatenate strings with
§Examples
use arr_rs::prelude::*;

let expected = Array::flat(vec!["a-a-a".to_string(), "b.b.b.b".to_string()]);
let arr = Array::flat(vec!["aaa".to_string(), "bbbb".to_string()]);
let sep = Array::flat(vec!["-".to_string(), ".".to_string()]).unwrap();
assert_eq!(expected, arr.join(&sep));
§Errors

may returns ArrayError

Source

fn partition( &self, sep: &Array<N>, ) -> Result<Array<Tuple3<N, N, N>>, ArrayError>

Partition each element around first occurrence of sep

§Arguments
  • sep - separator to split each string element
§Examples
use arr_rs::prelude::*;

let expected = Array::flat(vec![Tuple3("a".to_string(), "-".to_string(), "a-a".to_string()), Tuple3("b".to_string(), "-".to_string(), "b-b-b".to_string())]);
let arr = Array::flat(vec!["a-a-a".to_string(), "b-b-b-b".to_string()]);
assert_eq!(expected, ArrayStringManipulate::partition(&arr, &Array::single("-".to_string()).unwrap()));
§Errors

may returns ArrayError

Source

fn rpartition( &self, sep: &Array<N>, ) -> Result<Array<Tuple3<N, N, N>>, ArrayError>

Partition each element around last occurrence of sep

§Arguments
  • sep - separator to split each string element
§Examples
use arr_rs::prelude::*;

let expected = Array::flat(vec![Tuple3("a-a".to_string(), "-".to_string(), "a".to_string()), Tuple3("b-b-b".to_string(), "-".to_string(), "b".to_string())]);
let arr = Array::flat(vec!["a-a-a".to_string(), "b-b-b-b".to_string()]);
assert_eq!(expected, arr.rpartition(&Array::single("-".to_string()).unwrap()));
§Errors

may returns ArrayError

Source

fn split( &self, sep: Option<Array<N>>, max_split: Option<Array<usize>>, ) -> Result<Array<List<N>>, ArrayError>

Returns a list of the words in the string, using sep as the delimiter string.

§Arguments
  • sep - separator to split each string element. defaults to space
  • max_split - at most <max_split> splits are done
§Examples
use arr_rs::prelude::*;

let expected = Array::flat(vec![List(vec!["a".to_string(), "a".to_string(), "a".to_string()]), List(vec!["b".to_string(), "b".to_string(), "b".to_string(), "b".to_string()])]);
let arr = Array::flat(vec!["a-a-a".to_string(), "b-b-b-b".to_string()]).unwrap();
assert_eq!(expected, ArrayStringManipulate::split(&arr, Some(Array::single("-".to_string()).unwrap()), None));
§Errors

may returns ArrayError

Source

fn rsplit( &self, sep: Option<Array<N>>, max_split: Option<Array<usize>>, ) -> Result<Array<List<N>>, ArrayError>

Returns a list of the words in the string, using sep as the delimiter string.

§Arguments
  • sep - separator to split each string element. defaults to space
  • max_split - at most <max_split> splits are done
§Examples
use arr_rs::prelude::*;

let expected = Array::flat(vec![List(vec!["a".to_string(), "a".to_string(), "a".to_string()]), List(vec!["b".to_string(), "b".to_string(), "b".to_string(), "b".to_string()])]);
let arr = Array::flat(vec!["a-a-a".to_string(), "b-b-b-b".to_string()]).unwrap();
assert_eq!(expected, ArrayStringManipulate::rsplit(&arr, Some(Array::single("-".to_string()).unwrap()), None));
§Errors

may returns ArrayError

Source

fn splitlines( &self, keep_ends: Option<Array<bool>>, ) -> Result<Array<List<N>>, ArrayError>

Returns a list of the words in the string, using line break character as the delimiter string.

§Arguments
  • keep_ends - if true, line break character will be kept
§Examples
use arr_rs::prelude::*;

let expected = Array::flat(vec![List(vec!["aa".to_string(), "a".to_string()]), List(vec!["bb".to_string(), "bb".to_string()])]);
let arr = Array::flat(vec!["aa\na".to_string(), "bb\nbb".to_string()]).unwrap();
assert_eq!(expected, arr.splitlines(None));
§Errors

may returns ArrayError

Source

fn replace( &self, old: &Array<N>, new: &Array<N>, count: Option<usize>, ) -> Result<Array<N>, ArrayError>

Replaces all occurrences of with

§Arguments
  • old - string to replace
  • new - new string
  • count - maximum occurrences to replace
§Examples
use arr_rs::prelude::*;

let expected = Array::flat(vec!["new string".to_string()]);
let arr = Array::flat(vec!["old string".to_string()]);
let new = Array::flat(vec!["new".to_string()]).unwrap();
let old = Array::flat(vec!["old".to_string()]).unwrap();
assert_eq!(expected, arr.replace(&old, &new, None));
§Errors

may returns ArrayError

Source

fn strip(&self, chars: Option<Array<N>>) -> Result<Array<N>, ArrayError>

Trims leading and trailing characters

§Arguments
  • chars - characters to trim. defaults to whitespace
§Examples
use arr_rs::prelude::*;

let expected = Array::flat(vec!["b".to_string(), "bbbb".to_string()]);
let arr = Array::flat(vec!["aaba".to_string(), "ccbbbbc".to_string()]);
assert_eq!(expected, arr.strip(Some(Array::flat(vec!["a".to_string(), "c".to_string()]).unwrap())));
§Errors

may returns ArrayError

Source

fn lstrip(&self, chars: Option<Array<N>>) -> Result<Array<N>, ArrayError>

Trims leading characters

§Arguments
  • chars - characters to trim. defaults to whitespace
§Examples
use arr_rs::prelude::*;

let expected = Array::flat(vec!["ba".to_string(), "c".to_string()]);
let arr = Array::flat(vec!["aaba".to_string(), "bbbbc".to_string()]);
assert_eq!(expected, arr.lstrip(Some(Array::flat(vec!["a".to_string(), "b".to_string()]).unwrap())));
§Errors

may returns ArrayError

Source

fn rstrip(&self, chars: Option<Array<N>>) -> Result<Array<N>, ArrayError>

Trims trailing characters

§Arguments
  • chars - characters to trim. defaults to whitespace
§Examples
use arr_rs::prelude::*;

let expected = Array::flat(vec!["ba".to_string(), "c".to_string()]);
let arr = Array::flat(vec!["aaba".to_string(), "bbbbc".to_string()]);
assert_eq!(expected, arr.lstrip(Some(Array::flat(vec!["a".to_string(), "b".to_string()]).unwrap())));
§Errors

may returns ArrayError

Source

fn ljust( &self, width: &Array<usize>, fill_char: Option<Array<char>>, ) -> Result<Array<N>, ArrayError>

Left-justifies elements in a string of length of width

§Arguments
  • width - length of the resulting strings
  • fill_char - padding character to use. defaults to space
§Examples
use arr_rs::prelude::*;

let expected = Array::flat(vec!["aaa******".to_string(), "bbbb*****".to_string()]);
let arr = Array::flat(vec!["aaa".to_string(), "bbbb".to_string()]);
assert_eq!(expected, arr.ljust(&Array::single(9).unwrap(), Some(Array::single('*').unwrap())));
§Errors

may returns ArrayError

Source

fn rjust( &self, width: &Array<usize>, fill_char: Option<Array<char>>, ) -> Result<Array<N>, ArrayError>

Right-justifies elements in a string of length of width

§Arguments
  • width - length of the resulting strings
  • fill_char - padding character to use. defaults to space
§Examples
use arr_rs::prelude::*;

let expected = Array::flat(vec!["******aaa".to_string(), "*****bbbb".to_string()]);
let arr = Array::flat(vec!["aaa".to_string(), "bbbb".to_string()]);
assert_eq!(expected, arr.rjust(&Array::single(9).unwrap(), Some(Array::single('*').unwrap())));
§Errors

may returns ArrayError

Source

fn zfill(&self, width: usize) -> Result<Array<N>, ArrayError>

Return the numeric string left-filled with zeros

§Arguments
  • width - length of the resulting strings
§Examples
use arr_rs::prelude::*;

let expected = Array::flat(vec!["0005".to_string(), "-005".to_string()]);
let arr = Array::flat(vec!["5".to_string(), "-5".to_string()]);
assert_eq!(expected, arr.zfill(4));
§Errors

may returns ArrayError

Source

fn translate(&self, table: Vec<(char, char)>) -> Result<Array<N>, ArrayError>

Remove elements from delete_char vec and translate string remaining characters through table

§Arguments
  • table - chars to replace
  • delete_chars - chars to delete
§Examples
use arr_rs::prelude::*;

let expected = Array::flat(vec!["hewwd".to_string(), "wdrwd".to_string()]);
let arr = Array::flat(vec!["hello".to_string(), "world".to_string()]);
assert_eq!(expected, arr.translate(vec![('l', 'w'), ('o', 'd')]));
§Errors

may returns ArrayError

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<N: Alphanumeric> ArrayStringManipulate<N> for Result<Array<N>, ArrayError>

Source§

fn add(&self, other: &Array<N>) -> Self

Source§

fn multiply(&self, counts: &Array<usize>) -> Self

Source§

fn capitalize(&self) -> Self

Source§

fn lower(&self) -> Self

Source§

fn upper(&self) -> Self

Source§

fn swapcase(&self) -> Self

Source§

fn center(&self, width: &Array<usize>, fill_char: Option<Array<char>>) -> Self

Source§

fn join(&self, sep: &Array<N>) -> Self

Source§

fn partition( &self, sep: &Array<N>, ) -> Result<Array<Tuple3<N, N, N>>, ArrayError>

Source§

fn rpartition( &self, sep: &Array<N>, ) -> Result<Array<Tuple3<N, N, N>>, ArrayError>

Source§

fn split( &self, sep: Option<Array<N>>, max_split: Option<Array<usize>>, ) -> Result<Array<List<N>>, ArrayError>

Source§

fn rsplit( &self, sep: Option<Array<N>>, max_split: Option<Array<usize>>, ) -> Result<Array<List<N>>, ArrayError>

Source§

fn splitlines( &self, keep_ends: Option<Array<bool>>, ) -> Result<Array<List<N>>, ArrayError>

Source§

fn replace(&self, old: &Array<N>, new: &Array<N>, count: Option<usize>) -> Self

Source§

fn strip(&self, chars: Option<Array<N>>) -> Self

Source§

fn lstrip(&self, chars: Option<Array<N>>) -> Self

Source§

fn rstrip(&self, chars: Option<Array<N>>) -> Self

Source§

fn ljust(&self, width: &Array<usize>, fill_char: Option<Array<char>>) -> Self

Source§

fn rjust(&self, width: &Array<usize>, fill_char: Option<Array<char>>) -> Self

Source§

fn zfill(&self, width: usize) -> Self

Source§

fn translate(&self, table: Vec<(char, char)>) -> Self

Implementors§