pub trait ToSegments {
Show 15 methods
// Required methods
fn to_segments(&self, separator: &str) -> Vec<String>;
fn to_parts(&self, separator: &str) -> Vec<String>;
fn to_head(&self, separator: &str) -> String;
fn to_first(&self, separator: &str) -> String;
fn to_remainder_end(&self, separator: &str) -> String;
fn to_last(&self, separator: &str) -> String;
fn to_remainder_start(&self, separator: &str) -> String;
fn to_end(&self, separator: &str) -> String;
fn to_start(&self, separator: &str) -> String;
fn to_inner_segment(&self, groups: &[(&str, i32)]) -> Option<String>;
fn to_tail(&self, separator: &str) -> String;
fn to_head_tail(&self, separator: &str) -> (String, String);
fn to_start_end(&self, separator: &str) -> (String, String);
// Provided methods
fn to_segment(&self, separator: &str, index: i32) -> Option<String> { ... }
fn to_part(&self, separator: &str, index: i32) -> Option<String> { ... }
}
Expand description
Methods to split a longer strong on a separator and return a vector of strings, a tuple of two strings or single optional string segment Note some methods may return empty segments in the case of leading, trailing or repeated separators See notes below
Required Methods§
Sourcefn to_segments(&self, separator: &str) -> Vec<String>
fn to_segments(&self, separator: &str) -> Vec<String>
Extract a vector of non-empty strings from a string-like object with a given separator excluding leading, trailing or double separators
Sourcefn to_parts(&self, separator: &str) -> Vec<String>
fn to_parts(&self, separator: &str) -> Vec<String>
Extract a vector of strings from a string-like object with a given separator
Sourcefn to_head(&self, separator: &str) -> String
fn to_head(&self, separator: &str) -> String
Extract only the head before the first occurrence of a separator
Sourcefn to_first(&self, separator: &str) -> String
fn to_first(&self, separator: &str) -> String
Extract only the first segment before the first occurrence of a non-initial separator
Sourcefn to_remainder_end(&self, separator: &str) -> String
fn to_remainder_end(&self, separator: &str) -> String
Extract only the remainder after the first occurrence of a non-initial separator
Sourcefn to_last(&self, separator: &str) -> String
fn to_last(&self, separator: &str) -> String
Extract only the last segment after the last occurrence of a non-final separator
Sourcefn to_remainder_start(&self, separator: &str) -> String
fn to_remainder_start(&self, separator: &str) -> String
Extract only the beginning before the last segment following the last occurrence of a non-final separator
Sourcefn to_start(&self, separator: &str) -> String
fn to_start(&self, separator: &str) -> String
Extract the start before the last occurrence of the separator or the whole string if the separator is absent
Sourcefn to_inner_segment(&self, groups: &[(&str, i32)]) -> Option<String>
fn to_inner_segment(&self, groups: &[(&str, i32)]) -> Option<String>
Extract an inner segment via a set of separator + index tuples
Sourcefn to_head_tail(&self, separator: &str) -> (String, String)
fn to_head_tail(&self, separator: &str) -> (String, String)
extract the first and last parts after the first occurrence of the separator
Sourcefn to_start_end(&self, separator: &str) -> (String, String)
fn to_start_end(&self, separator: &str) -> (String, String)
extract the first and last parts after the last occurrence of the separator
Provided Methods§
Sourcefn to_segment(&self, separator: &str, index: i32) -> Option<String>
fn to_segment(&self, separator: &str, index: i32) -> Option<String>
Extract a non-empty segment identified by its index from the components of a string with a given separator e.g. String::from(“/User/maria/Documents”) .to_segment(1) yields “maria” with the leading slash separator ignored A negative index parameter will start from the end ignoring trailing separators
Implementations on Foreign Types§
Source§impl ToSegments for str
Implement string segment split and capture method for String
impl ToSegments for str
Implement string segment split and capture method for String
Source§fn to_parts(&self, separator: &str) -> Vec<String>
fn to_parts(&self, separator: &str) -> Vec<String>
Splits a string on the exact separator, whether initial, final or repeated. May yield empty segments
Source§fn to_segments(&self, separator: &str) -> Vec<String>
fn to_segments(&self, separator: &str) -> Vec<String>
Splits a string on a separator, but only returns an array of non-empty strings skipping leading, trailing or repeated separators that may otherwise yield empty strings
Source§fn to_head(&self, separator: &str) -> String
fn to_head(&self, separator: &str) -> String
Extract only the head as a string. If the separator is absent return the whole string
Source§fn to_last(&self, separator: &str) -> String
fn to_last(&self, separator: &str) -> String
Extract only the last segment after the last occurrence of a non-final separator
Source§fn to_start(&self, separator: &str) -> String
fn to_start(&self, separator: &str) -> String
extract the start before last occurrence of the separator or, if absent, return the whole string
Source§fn to_tail(&self, separator: &str) -> String
fn to_tail(&self, separator: &str) -> String
extract the remainder after the first split or the whole string if the separator is absent
Source§fn to_first(&self, separator: &str) -> String
fn to_first(&self, separator: &str) -> String
Extract only the first segment before the first occurrence of a non-initial separator
Source§fn to_remainder_end(&self, separator: &str) -> String
fn to_remainder_end(&self, separator: &str) -> String
Extract only the remainder after the first occurrence of a non-initial separator
Source§fn to_remainder_start(&self, separator: &str) -> String
fn to_remainder_start(&self, separator: &str) -> String
Extract only the beginning before the last segment following the last occurrence of a non-final separator
Source§fn to_inner_segment(&self, groups: &[(&str, i32)]) -> Option<String>
fn to_inner_segment(&self, groups: &[(&str, i32)]) -> Option<String>
extract an inner segment via a set of tuples with separators and indices. e.g. [(“/”, 1), (“-”, 2)] applied to “pictures/holiday-france-1983/originals” would match “1983” as an optional string