std_helper/string/split_at/string.rs
1use super::StrHelper;
2
3impl StrHelper {
4 /// split ```self''' at index and get ```(Option<String>, Option<String>)```.
5 ///
6 /// # Example:
7 /// ```
8 /// #[macro_use] extern crate std_helper;
9 /// use std_helper::StrHelper;
10 ///
11 /// let helper = str!("Crab is Rust!");
12 ///
13 /// let crab = helper.split_string_at(4).0.unwrap();
14 /// assert_eq!(crab, "Crab");
15 /// ```
16 pub fn split_string_at(&self, mid: usize) -> (Option<String>, Option<String>) {
17 let values = self
18 .string
19 .split_at(mid);
20
21 (Some(values.0.to_string()), Some(values.1.to_string()))
22 }
23
24 /// split ```self''' at indexes and get ```String```.
25 ///
26 /// # Example:
27 /// ```
28 /// #[macro_use] extern crate std_helper;
29 /// use std_helper::StrHelper;
30 ///
31 /// let helper = str!("Crab is Rust!");
32 ///
33 /// let is = helper.split_string_on_the_sides_at((5, 7)).unwrap();
34 /// assert_eq!(is, "is");
35 /// ```
36 pub fn split_string_on_the_sides_at(&self, mid: (usize, usize)) -> Option<String> {
37 let v = self
38 .split_str_on_the_sides_at(mid)?.to_string();
39
40 Some(v)
41 }
42}