mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Make util::str::str_join operate on Iterators
This commit is contained in:
parent
8547d132f9
commit
2857e547be
1 changed files with 4 additions and 2 deletions
|
@ -326,8 +326,10 @@ pub unsafe fn c_str_to_string(s: *const c_char) -> String {
|
||||||
from_utf8(CStr::from_ptr(s).to_bytes()).unwrap().to_owned()
|
from_utf8(CStr::from_ptr(s).to_bytes()).unwrap().to_owned()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn str_join<T: AsRef<str>>(strs: &[T], join: &str) -> String {
|
pub fn str_join<I, T>(strs: I, join: &str) -> String
|
||||||
strs.iter().fold(String::new(), |mut acc, s| {
|
where I: IntoIterator<Item=T>, T: AsRef<str>,
|
||||||
|
{
|
||||||
|
strs.into_iter().fold(String::new(), |mut acc, s| {
|
||||||
if !acc.is_empty() { acc.push_str(join); }
|
if !acc.is_empty() { acc.push_str(join); }
|
||||||
acc.push_str(s.as_ref());
|
acc.push_str(s.as_ref());
|
||||||
acc
|
acc
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue