pub trait ToSegments {
Show 13 methods // Required methods fn to_segments(&self, separator: &str) -> Vec<Self> where Self: Sized; fn to_parts(&self, separator: &str) -> Vec<Self> where Self: Sized; fn to_head(&self, separator: &str) -> Self where Self: Sized; fn to_first(&self, separator: &str) -> Self where Self: Sized; fn to_remainder_end(&self, separator: &str) -> Self where Self: Sized; fn to_last(&self, separator: &str) -> Self where Self: Sized; fn to_remainder_start(&self, separator: &str) -> Self where Self: Sized; fn to_end(&self, separator: &str) -> Self where Self: Sized; fn to_segment(&self, separator: &str, index: i32) -> Option<Self> where Self: Sized; fn to_inner_segment(&self, groups: &[(&str, i32)]) -> Option<Self> where Self: Sized; fn to_tail(&self, separator: &str) -> Self where Self: Sized; fn to_head_tail(&self, separator: &str) -> (Self, Self) where Self: Sized; fn to_start_end(&self, separator: &str) -> (Self, Self) where Self: Sized;
}
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§

source

fn to_segments(&self, separator: &str) -> Vec<Self>
where Self: Sized,

Extract a vector of non-empty strings from a string-like object with a given separator excluding leading, trailing or double separators

source

fn to_parts(&self, separator: &str) -> Vec<Self>
where Self: Sized,

Extract a vector of strings from a string-like object with a given separator

source

fn to_head(&self, separator: &str) -> Self
where Self: Sized,

Extract only the head before the first occurrence of a separator

source

fn to_first(&self, separator: &str) -> Self
where Self: Sized,

Extract only the first segment before the first occurrence of a non-initial separator

source

fn to_remainder_end(&self, separator: &str) -> Self
where Self: Sized,

Extract only the remainder after the first occurrence of a non-initial separator

source

fn to_last(&self, separator: &str) -> Self
where Self: Sized,

Extract only the last segment after the last occurrence of a non-final separator

source

fn to_remainder_start(&self, separator: &str) -> Self
where Self: Sized,

Extract only the beginning before the last segment following the last occurrence of a non-final separator

source

fn to_end(&self, separator: &str) -> Self
where Self: Sized,

Extract only the last segment

source

fn to_segment(&self, separator: &str, index: i32) -> Option<Self>
where Self: Sized,

Extract a string-like segment identified by its index from the components of a string with a given separator e.g. String::from(“10/11/2024”) .to_segment(1) yields “11”

source

fn to_inner_segment(&self, groups: &[(&str, i32)]) -> Option<Self>
where Self: Sized,

source

fn to_tail(&self, separator: &str) -> Self
where Self: Sized,

extract the remainder after the head

source

fn to_head_tail(&self, separator: &str) -> (Self, Self)
where Self: Sized,

extract the first and last parts after the first occurrence of the separator

source

fn to_start_end(&self, separator: &str) -> (Self, Self)
where Self: Sized,

extract the first and last parts after the last occurrence of the separator

Implementations on Foreign Types§

source§

impl ToSegments for String

source§

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>

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_last(&self, separator: &str) -> String

Extract only the last segment after the last occurrence of a non-final separator

source§

fn to_end(&self, separator: &str) -> String

extract the last segment whether empty or not

source§

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

Extract only the remainder after the first occurrence of a non-initial separator

source§

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_segment(&self, separator: &str, index: i32) -> Option<String>

Extract an indexed segment yielded by splitting a string. A negative index parameter will start from the end

source§

fn to_inner_segment(&self, groups: &[(&str, i32)]) -> Option<String>

extract inner segment via a set of tuples with separators and indices.

source§

fn to_head_tail(&self, separator: &str) -> (String, String)

Extract a tuple of the head and remainder, like split_once but returns Strings

source§

fn to_start_end(&self, separator: &str) -> (String, String)

Extract a tuple of the tail and remainder, like split_once in reverse and returning strings

source§

fn to_head(&self, separator: &str) -> String

source§

fn to_tail(&self, separator: &str) -> String

Implementors§