pub trait ArrayStringManipulate<N: Alphanumeric>{
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§
Sourcefn add(&self, other: &Array<N>) -> Result<Array<N>, ArrayError>
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
Sourcefn multiply(&self, counts: &Array<usize>) -> Result<Array<N>, ArrayError>
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
Sourcefn capitalize(&self) -> Result<Array<N>, ArrayError>
fn capitalize(&self) -> Result<Array<N>, ArrayError>
Sourcefn lower(&self) -> Result<Array<N>, ArrayError>
fn lower(&self) -> Result<Array<N>, ArrayError>
Sourcefn upper(&self) -> Result<Array<N>, ArrayError>
fn upper(&self) -> Result<Array<N>, ArrayError>
Sourcefn swapcase(&self) -> Result<Array<N>, ArrayError>
fn swapcase(&self) -> Result<Array<N>, ArrayError>
Sourcefn center(
&self,
width: &Array<usize>,
fill_char: Option<Array<char>>,
) -> Result<Array<N>, ArrayError>
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 stringsfill_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
Sourcefn join(&self, sep: &Array<N>) -> Result<Array<N>, ArrayError>
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
Sourcefn partition(
&self,
sep: &Array<N>,
) -> Result<Array<Tuple3<N, N, N>>, ArrayError>
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
Sourcefn rpartition(
&self,
sep: &Array<N>,
) -> Result<Array<Tuple3<N, N, N>>, ArrayError>
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
Sourcefn split(
&self,
sep: Option<Array<N>>,
max_split: Option<Array<usize>>,
) -> Result<Array<List<N>>, ArrayError>
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 spacemax_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
Sourcefn rsplit(
&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>
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 spacemax_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
Sourcefn splitlines(
&self,
keep_ends: Option<Array<bool>>,
) -> Result<Array<List<N>>, ArrayError>
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
Sourcefn replace(
&self,
old: &Array<N>,
new: &Array<N>,
count: Option<usize>,
) -> Result<Array<N>, ArrayError>
fn replace( &self, old: &Array<N>, new: &Array<N>, count: Option<usize>, ) -> Result<Array<N>, ArrayError>
Replaces all occurrences of
§Arguments
old
- string to replacenew
- new stringcount
- 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
Sourcefn strip(&self, chars: Option<Array<N>>) -> Result<Array<N>, ArrayError>
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
Sourcefn lstrip(&self, chars: Option<Array<N>>) -> Result<Array<N>, ArrayError>
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
Sourcefn rstrip(&self, chars: Option<Array<N>>) -> Result<Array<N>, ArrayError>
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
Sourcefn ljust(
&self,
width: &Array<usize>,
fill_char: Option<Array<char>>,
) -> Result<Array<N>, ArrayError>
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 stringsfill_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
Sourcefn rjust(
&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>
Right-justifies elements in a string of length of width
§Arguments
width
- length of the resulting stringsfill_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
Sourcefn zfill(&self, width: usize) -> Result<Array<N>, ArrayError>
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
Sourcefn translate(&self, table: Vec<(char, char)>) -> Result<Array<N>, ArrayError>
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 replacedelete_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.