1 | use alloc::string::String; |
2 | use core::borrow::Borrow; |
3 | |
4 | use crate::{TiSlice, TiVec}; |
5 | |
6 | /// A helper trait for [`TiSlice::join`](crate::TiSlice#method.join) |
7 | pub trait Join<Separator> { |
8 | /// The resulting type after concatenation |
9 | type Output; |
10 | |
11 | /// Implementation of [`TiSlice::join`](crate::TiSlice#method.join) |
12 | fn join(slice: &Self, sep: Separator) -> Self::Output; |
13 | } |
14 | |
15 | impl<K, V: Borrow<str>> Join<&str> for TiSlice<K, V> { |
16 | type Output = String; |
17 | |
18 | #[inline ] |
19 | fn join(slice: &Self, sep: &str) -> Self::Output { |
20 | slice.raw.join(sep) |
21 | } |
22 | } |
23 | |
24 | impl<K, T: Clone, V: Borrow<[T]>> Join<&T> for TiSlice<K, V> { |
25 | type Output = TiVec<K, T>; |
26 | |
27 | #[inline ] |
28 | fn join(slice: &Self, sep: &T) -> Self::Output { |
29 | slice.raw.join(sep).into() |
30 | } |
31 | } |
32 | |
33 | impl<K, T: Clone, V: Borrow<[T]>> Join<&[T]> for TiSlice<K, V> { |
34 | type Output = TiVec<K, T>; |
35 | |
36 | #[inline ] |
37 | fn join(slice: &Self, sep: &[T]) -> Self::Output { |
38 | slice.raw.join(sep).into() |
39 | } |
40 | } |
41 | |