abi_stable/std_types/string/
iters.rs
1use super::*;
2
3pub struct IntoIter {
9 pub(super) _buf: RString,
10 pub(super) iter: Chars<'static>,
11}
12
13unsafe impl Send for IntoIter {}
14unsafe impl Sync for IntoIter {}
15
16impl IntoIter {
17 pub fn as_str(&self) -> &str {
36 self.iter.as_str()
37 }
38}
39
40impl Iterator for IntoIter {
41 type Item = char;
42
43 #[inline]
44 fn next(&mut self) -> Option<char> {
45 self.iter.next()
46 }
47
48 fn size_hint(&self) -> (usize, Option<usize>) {
49 self.iter.size_hint()
50 }
51}
52
53impl DoubleEndedIterator for IntoIter {
54 #[inline]
55 fn next_back(&mut self) -> Option<char> {
56 self.iter.next_back()
57 }
58}
59
60impl FusedIterator for IntoIter {}
61
62pub struct Drain<'a> {
67 pub(super) string: *mut RString,
68 pub(super) removed: Range<usize>,
69 pub(super) iter: Chars<'a>,
70 pub(super) variance: PhantomData<&'a mut [char]>,
71}
72
73impl<'a> fmt::Debug for Drain<'a> {
74 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
75 f.pad("Drain { .. }")
76 }
77}
78
79unsafe impl<'a> Sync for Drain<'a> {}
80unsafe impl<'a> Send for Drain<'a> {}
81
82impl<'a> Drain<'a> {
83 pub fn as_str(&self) -> &str {
107 self.iter.as_str()
108 }
109}
110
111impl<'a> Drop for Drain<'a> {
112 fn drop(&mut self) {
113 unsafe {
114 let self_vec = &mut (*self.string).inner;
115 if self.removed.start <= self.removed.end && self.removed.end <= self_vec.len() {
116 self_vec.drain(self.removed.start..self.removed.end);
117 }
118 }
119 }
120}
121
122impl<'a> Iterator for Drain<'a> {
123 type Item = char;
124
125 #[inline]
126 fn next(&mut self) -> Option<char> {
127 self.iter.next()
128 }
129
130 fn size_hint(&self) -> (usize, Option<usize>) {
131 self.iter.size_hint()
132 }
133}
134
135impl<'a> DoubleEndedIterator for Drain<'a> {
136 #[inline]
137 fn next_back(&mut self) -> Option<char> {
138 self.iter.next_back()
139 }
140}
141
142impl<'a> FusedIterator for Drain<'a> {}