pub trait ArrayStringIndexing<N: Alphanumeric>{
// Required methods
fn str_len(&self) -> Result<Array<usize>, ArrayError>;
fn count(&self, sub: &Array<N>) -> Result<Array<usize>, ArrayError>;
fn starts_with(&self, prefix: &Array<N>) -> Result<Array<bool>, ArrayError>;
fn ends_with(&self, suffix: &Array<N>) -> Result<Array<bool>, ArrayError>;
fn find(&self, sub: &Array<N>) -> Result<Array<isize>, ArrayError>;
fn rfind(&self, sub: &Array<N>) -> Result<Array<isize>, ArrayError>;
fn index(&self, sub: &Array<N>) -> Result<Array<isize>, ArrayError>;
fn rindex(&self, sub: &Array<N>) -> Result<Array<isize>, ArrayError>;
}
Expand description
ArrayTrait
- Alphanumeric Array operations
Required Methods§
Sourcefn count(&self, sub: &Array<N>) -> Result<Array<usize>, ArrayError>
fn count(&self, sub: &Array<N>) -> Result<Array<usize>, ArrayError>
Returns an array with the number of non-overlapping occurrences of substring sub
§Arguments
sub
- substring to search for
§Examples
use arr_rs::prelude::*;
let expected = Array::flat(vec![3, 2, 1]);
let arr = Array::flat(vec!["AaAaAa".to_string(), "aAaAaA".to_string(), "bbAabb".to_string()]);
assert_eq!(expected, arr.count(&Array::single("Aa".to_string()).unwrap()));
let expected = Array::flat(vec![1]);
let arr = Array::flat(vec!["AaAaAa".to_string()]);
assert_eq!(expected, arr.count(&Array::single("AaAa".to_string()).unwrap()));
§Errors
may returns ArrayError
Sourcefn starts_with(&self, prefix: &Array<N>) -> Result<Array<bool>, ArrayError>
fn starts_with(&self, prefix: &Array<N>) -> Result<Array<bool>, ArrayError>
Checks if string element starts with prefix
§Arguments
prefix
- substring to search for
§Examples
use arr_rs::prelude::*;
let expected = Array::flat(vec![true, false, false]);
let arr = Array::flat(vec!["AaAaAa".to_string(), "aAaAaA".to_string(), "bbAabb".to_string()]);
assert_eq!(expected, arr.starts_with(&Array::single("Aa".to_string()).unwrap()));
§Errors
may returns ArrayError
Sourcefn ends_with(&self, suffix: &Array<N>) -> Result<Array<bool>, ArrayError>
fn ends_with(&self, suffix: &Array<N>) -> Result<Array<bool>, ArrayError>
Checks if string element ends with suffix
§Arguments
suffix
- substring to search for
§Examples
use arr_rs::prelude::*;
let expected = Array::flat(vec![false, true, false]);
let arr = Array::flat(vec!["AaAaAa".to_string(), "aAaAaA".to_string(), "bbAabb".to_string()]);
assert_eq!(expected, arr.ends_with(&Array::single("aA".to_string()).unwrap()));
§Errors
may returns ArrayError
Sourcefn find(&self, sub: &Array<N>) -> Result<Array<isize>, ArrayError>
fn find(&self, sub: &Array<N>) -> Result<Array<isize>, ArrayError>
For each element, return the lowest index in the string where substring sub is found
§Arguments
sub
- substring to search for
§Examples
use arr_rs::prelude::*;
let expected = Array::flat(vec![1, 0, -1]);
let arr = Array::flat(vec!["AaAaAa".to_string(), "aAaAaA".to_string(), "bbAabb".to_string()]);
assert_eq!(expected, arr.find(&Array::single("aA".to_string()).unwrap()));
§Errors
may returns ArrayError
Sourcefn rfind(&self, sub: &Array<N>) -> Result<Array<isize>, ArrayError>
fn rfind(&self, sub: &Array<N>) -> Result<Array<isize>, ArrayError>
For each element, return the highest index in the string where substring sub is found
§Arguments
sub
- substring to search for
§Examples
use arr_rs::prelude::*;
let expected = Array::flat(vec![3, 4, -1]);
let arr = Array::flat(vec!["AaAaAa".to_string(), "aAaAaA".to_string(), "bbAabb".to_string()]);
assert_eq!(expected, arr.rfind(&Array::single("aA".to_string()).unwrap()));
§Errors
may returns ArrayError
Sourcefn index(&self, sub: &Array<N>) -> Result<Array<isize>, ArrayError>
fn index(&self, sub: &Array<N>) -> Result<Array<isize>, ArrayError>
For each element, return the lowest index in the string where substring sub is found;
alias on find
§Arguments
sub
- substring to search for
§Examples
use arr_rs::prelude::*;
let expected = Array::flat(vec![1, 0, -1]);
let arr = Array::flat(vec!["AaAaAa".to_string(), "aAaAaA".to_string(), "bbAabb".to_string()]);
assert_eq!(expected, arr.index(&Array::single("aA".to_string()).unwrap()));
§Errors
may returns ArrayError
Sourcefn rindex(&self, sub: &Array<N>) -> Result<Array<isize>, ArrayError>
fn rindex(&self, sub: &Array<N>) -> Result<Array<isize>, ArrayError>
For each element, return the highest index in the string where substring sub is found;
alias on rfind
§Arguments
sub
- substring to search for
§Examples
use arr_rs::prelude::*;
let expected = Array::flat(vec![3, 4, -1]);
let arr = Array::flat(vec!["AaAaAa".to_string(), "aAaAaA".to_string(), "bbAabb".to_string()]);
assert_eq!(expected, arr.rindex(&Array::single("aA".to_string()).unwrap()));
§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.