pub trait ArrayStringIndexing<N: Alphanumeric>where
    Self: Sized + Clone,{
    // 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§

source

fn str_len(&self) -> Result<Array<usize>, ArrayError>

Return string.len() element-wise

Examples
use arr_rs::prelude::*;

let expected = Array::flat(vec![6, 9, 3]);
let arr = Array::flat(vec!["AaAaAa".to_string(), "aAaAaAacc".to_string(), "abc".to_string()]);
assert_eq!(expected, arr.str_len());
source

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()));
source

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()));
source

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()));
source

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()));
source

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()));
source

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()));
source

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()));

Implementations on Foreign Types§

source§

impl<N: Alphanumeric> ArrayStringIndexing<N> for Result<Array<N>, ArrayError>

source§

fn str_len(&self) -> Result<Array<usize>, ArrayError>

source§

fn count(&self, sub: &Array<N>) -> Result<Array<usize>, ArrayError>

source§

fn starts_with(&self, prefix: &Array<N>) -> Result<Array<bool>, ArrayError>

source§

fn ends_with(&self, suffix: &Array<N>) -> Result<Array<bool>, ArrayError>

source§

fn find(&self, sub: &Array<N>) -> Result<Array<isize>, ArrayError>

source§

fn rfind(&self, sub: &Array<N>) -> Result<Array<isize>, ArrayError>

source§

fn index(&self, sub: &Array<N>) -> Result<Array<isize>, ArrayError>

source§

fn rindex(&self, sub: &Array<N>) -> Result<Array<isize>, ArrayError>

Implementors§