Function Join

Source
pub fn Join(elems: Vec<&[byte]>, sep: impl AsRef<[byte]>) -> Vec<byte> 
Expand description

Join concatenates the elements of s to create a new byte slice. The separator sep is placed between elements in the resulting slice.

zh-cn 将一系列字符串连接为一个字符串,之间用sep来分隔。

§Example

use gostd_bytes as bytes;

let s = vec!["foo".as_bytes(), "bar".as_bytes(), "baz".as_bytes()];

assert_eq!("foo, bar, baz".as_bytes(),bytes::Join(s,", "));

let list: Vec<&[u8]> = [[1, 2], [3, 4]].iter().map(|x|x.as_slice()).collect();
assert_eq!(bytes::Join(list.clone(),&[0, 0][..]), [1, 2, 0, 0, 3, 4]);
assert_eq!(bytes::Join(list,&[0, 0][..]), [1, 2, 0, 0, 3, 4].as_slice());