1use super::separator::Separator;
2
3pub trait Separators: Copy {
5 type Separator: Separator;
7
8 type Residual: Separators;
10
11 fn split(self) -> (Option<Self::Separator>, Self::Residual);
15}
16
17impl<T: Separator + Copy> Separators for T {
18 type Separator = Self;
19 type Residual = Self;
20
21 #[inline]
22 fn split(self) -> (Option<Self::Separator>, Self::Residual) {
23 (Some(self), self)
24 }
25}
26
27impl<'r, T: Separator, const N: usize> Separators for &'r [T; N] {
28 type Separator = &'r T;
29 type Residual = &'r [T];
30
31 #[inline]
32 fn split(self) -> (Option<Self::Separator>, Self::Residual) {
33 Separators::split(self.as_slice())
34 }
35}
36
37impl<'r, T: Separator> Separators for &'r [T] {
38 type Separator = &'r T;
39 type Residual = &'r [T];
40
41 #[inline]
42 fn split(self) -> (Option<Self::Separator>, Self::Residual) {
43 if let Some((first, residual)) = self.split_first() {
44 (Some(first), residual)
45 } else {
46 (None, self)
47 }
48 }
49}
50
51#[derive(Clone, Copy, Default)]
53pub struct DefaultSeparator;
54
55impl DefaultSeparator {
56 #[inline]
58 pub const fn new() -> Self {
59 Self
60 }
61}
62
63impl Separators for DefaultSeparator {
64 type Separator = &'static str;
65 type Residual = Self;
66
67 #[inline]
68 fn split(self) -> (Option<Self::Separator>, Self) {
69 (None, self)
70 }
71}