pub trait Join {
type Item;
// Required methods
fn join(&mut self, sep: &str) -> String
where Self::Item: Display;
fn join_format<F>(&mut self, sep: &str, f: F) -> String
where F: Fn(&Self::Item) -> String;
}Required Associated Types§
Required Methods§
Sourcefn join(&mut self, sep: &str) -> String
fn join(&mut self, sep: &str) -> String
Returns a string that contains the items separated by the separator string.
use stringx::Join;
assert_eq!((1..=5).join(", "), "1, 2, 3, 4, 5")Sourcefn join_format<F>(&mut self, sep: &str, f: F) -> String
fn join_format<F>(&mut self, sep: &str, f: F) -> String
Works like Join::join but takes an additional formatting closure as argument.
use stringx::Join;
let string = [Some(8379), Some(990), None, Some(974385)]
.iter()
.join_format(" | ", |item| match item {
Some(number) => number.to_string(),
None => "_".into(),
});
assert_eq!(string, "8379 | 990 | _ | 974385");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.