pub fn join_str<I, S>(
elements: impl Join<I>,
sep: S,
) -> Joiner<impl Iterator<Item = impl Display>, impl Display>
Expand description
Join anything that implements Join
when elements don’t implement
std::fmt::Display
, but implement AsRef<str>
instead.
§Examples
use join_string::join_str;
assert_eq!(
join_str(&["foo", "bar", "baz"], ", ").into_string(),
"foo, bar, baz"
);
assert_eq!(
join_str([
&"foo".to_owned(),
&"bar".to_owned(),
&"baz".to_owned()
].as_slice(), ", ").into_string(),
"foo, bar, baz"
);
assert_eq!(
join_str(&vec!["foo", "bar", "baz"], ", ").into_string(),
"foo, bar, baz"
);
assert_eq!(
join_str([
"foo".to_owned(),
"bar".to_owned(),
"baz".to_owned()
].iter().rev(), ", ").into_string(),
"baz, bar, foo"
);