1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
use crate::{prelude::*, utils::IntoLossy};
use core::fmt::{self, Debug, Formatter};
use core::{cmp::Ordering, hash::Hash, hash::Hasher, iter::FusedIterator};
#[derive(Clone, Default)]
pub struct Drain<S: Capacity>(pub(crate) ArrayString<S>, pub(crate) u8);
impl<SIZE> Debug for Drain<SIZE>
where
SIZE: Capacity,
{
#[inline]
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
f.debug_tuple("Drain")
.field(&self.0)
.field(&self.1)
.finish()
}
}
impl<SIZE> PartialEq for Drain<SIZE>
where
SIZE: Capacity,
{
#[inline]
fn eq(&self, other: &Self) -> bool {
self.as_str().eq(other.as_str())
}
}
impl<SIZE: Capacity> Eq for Drain<SIZE> {}
impl<SIZE> Ord for Drain<SIZE>
where
SIZE: Capacity,
{
#[inline]
fn cmp(&self, other: &Self) -> Ordering {
self.as_str().cmp(other.as_str())
}
}
impl<SIZE> PartialOrd for Drain<SIZE>
where
SIZE: Capacity,
{
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl<SIZE> Hash for Drain<SIZE>
where
SIZE: Capacity,
{
#[inline]
fn hash<H: Hasher>(&self, hasher: &mut H) {
self.as_str().hash(hasher)
}
}
impl<SIZE: Capacity + Copy> Copy for Drain<SIZE> where SIZE::Array: Copy {}
impl<S: Capacity> Drain<S> {
#[inline]
pub fn as_str(&self) -> &str {
unsafe { self.0.as_str().get_unchecked(self.1.into()..) }
}
}
impl<S: Capacity> Iterator for Drain<S> {
type Item = char;
#[inline]
fn next(&mut self) -> Option<Self::Item> {
self.0
.as_str()
.get(self.1.into()..)
.and_then(|s| s.chars().next())
.map(|c| {
self.1 = self.1.saturating_add(c.len_utf8().into_lossy());
c
})
}
}
impl<S: Capacity> DoubleEndedIterator for Drain<S> {
#[inline]
fn next_back(&mut self) -> Option<Self::Item> {
self.0.pop()
}
}
impl<S: Capacity> FusedIterator for Drain<S> {}