Trait ArrayStringIndexing

Source
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());
§Errors

may returns ArrayError

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

may returns ArrayError

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

may returns ArrayError

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

may returns ArrayError

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

may returns ArrayError

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

may returns ArrayError

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

may returns ArrayError

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