Debian Codegraph @

debian/missing-sources/itertools/src/format.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/::Cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/Cell#;
2 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/;
3
4 /// Format all iterator elements lazily, separated by `sep`.
5 ///
6 /// The format value can only be formatted once, after that the iterator is
7 /// exhausted.
8 ///
9 /// See [`.format_with()`](crate::Itertools::format_with) for more information.
10 pub struct FormatWithrust-analyzer cargo itertools 0.14.0 format/FormatWith#<'a, I, F> {
11 seprust-analyzer cargo itertools 0.14.0 format/FormatWith#sep.: &'a str,
12 /// `FormatWith` uses interior mutability because `Display::fmt` takes `&self`.
13 innerrust-analyzer cargo itertools 0.14.0 format/FormatWith#inner.: Cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/Cell#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(I, F)>>,
14 }
15
16 /// Format all iterator elements lazily, separated by `sep`.
17 ///
18 /// The format value can only be formatted once, after that the iterator is
19 /// exhausted.
20 ///
21 /// See [`.format()`](crate::Itertools::format)
22 /// for more information.
23 pub struct Formatrust-analyzer cargo itertools 0.14.0 format/Format#<'a, I> {
24 seprust-analyzer cargo itertools 0.14.0 format/Format#sep.: &'a str,
25 /// `Format` uses interior mutability because `Display::fmt` takes `&self`.
26 innerrust-analyzer cargo itertools 0.14.0 format/Format#inner.: Cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/Cell#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<I>>,
27 }
28
29 pub fn new_formatrust-analyzer cargo itertools 0.14.0 format/new_format().<I, F>(iter: I, separator: &str, f: F) -> FormatWithrust-analyzer cargo itertools 0.14.0 format/FormatWith#<'_, I, F>
30 where
31 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#,
32 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#, &mut dyn FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&dyn fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result#) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result#,
33 {
34 FormatWithrust-analyzer cargo itertools 0.14.0 format/FormatWith# {
35 seprust-analyzer cargo itertools 0.14.0 format/FormatWith#sep.: separator,
36 innerrust-analyzer cargo itertools 0.14.0 format/FormatWith#inner.: Cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/Cell#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]new().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((iter, f))),
37 }
38 }
39
40 pub fn new_format_defaultrust-analyzer cargo itertools 0.14.0 format/new_format_default().<I>(iter: I, separator: &str) -> Formatrust-analyzer cargo itertools 0.14.0 format/Format#<'_, I>
41 where
42 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#,
43 {
44 Formatrust-analyzer cargo itertools 0.14.0 format/Format# {
45 seprust-analyzer cargo itertools 0.14.0 format/Format#sep.: separator,
46 innerrust-analyzer cargo itertools 0.14.0 format/Format#inner.: Cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/Cell#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]new().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(iter)),
47 }
48 }
49
50 impl<I, F> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for FormatWithrust-analyzer cargo itertools 0.14.0 format/FormatWith#<'_, I, F>
51 where
52 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#,
53 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#, &mut dyn FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&dyn fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result#) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result#,
54 {
55 fn fmtrust-analyzer cargo itertools 0.14.0 format/impl#[`FormatWith<'_, I, F>`][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
56 let (mut iter, mut format) = match self.innerrust-analyzer cargo itertools 0.14.0 format/FormatWith#inner..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]take().() {
57 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(t) => t,
58 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("FormatWith: was already formatted once"),
59 };
60
61 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(fst) = iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().() {
62 format(fst, &mut |disp: &dyn fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#| disp.fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#fmt().(f))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
63 iter.try_for_eachrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#try_for_each().(|elt| {
64 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.seprust-analyzer cargo itertools 0.14.0 format/FormatWith#sep..is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() {
65 f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().(self.seprust-analyzer cargo itertools 0.14.0 format/FormatWith#sep.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
66 }
67 format(elt, &mut |disp: &dyn fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#| disp.fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#fmt().(f))
68 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
69 }
70 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
71 }
72 }
73
74 impl<I, F> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for FormatWithrust-analyzer cargo itertools 0.14.0 format/FormatWith#<'_, I, F>
75 where
76 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#,
77 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#, &mut dyn FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&dyn fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result#) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result#,
78 {
79 fn fmtrust-analyzer cargo itertools 0.14.0 format/impl#[`FormatWith<'_, I, F>`][Debug]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
80 fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#::fmtrust-analyzer cargo itertools 0.14.0 format/impl#[`FormatWith<'_, I, F>`][Display]fmt().(self, f)
81 }
82 }
83
84 impl<I> Formatrust-analyzer cargo itertools 0.14.0 format/Format#<'_, I>
85 where
86 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#,
87 {
88 fn formatrust-analyzer cargo itertools 0.14.0 format/impl#[`Format<'_, I>`]format().(
89 &self,
90 f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#,
91 cb: fn(&I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#, &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result#,
92 ) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
93 let mut iter = match self.innerrust-analyzer cargo itertools 0.14.0 format/Format#inner..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]take().() {
94 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(t) => t,
95 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Format: was already formatted once"),
96 };
97
98 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(fst) = iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().() {
99 cb(&fst, f)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
100 iter.try_for_eachrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#try_for_each().(|elt| {
101 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.seprust-analyzer cargo itertools 0.14.0 format/Format#sep..is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() {
102 f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().(self.seprust-analyzer cargo itertools 0.14.0 format/Format#sep.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
103 }
104 cb(&elt, f)
105 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
106 }
107 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
108 }
109 }
110
111 macro_rules! impl_formatrust-analyzer cargo itertools 0.14.0 format/impl_format! {
112 ($($fmt_trait:ident)*) => {
113 $(
114 impl<'a, I> fmt::$fmt_trait for Format<'a, I>
115 where I: Iterator,
116 I::Item: fmt::$fmt_trait,
117 {
118 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
119 self.format(f, fmt::$fmt_trait::fmt)
120 }
121 }
122 )*
123 }
124 }
125
126 impl_formatrust-analyzer cargo itertools 0.14.0 format/impl_format!! {Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# UpperExprust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/UpperExp# LowerExprust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/LowerExp# UpperHexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/UpperHex# LowerHexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/LowerHex# Octalrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Octal# Binaryrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Binary# Pointerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Pointer#}
127
128 impl<I, F> Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# for FormatWithrust-analyzer cargo itertools 0.14.0 format/FormatWith#<'_, I, F>
129 where
130 (I, F): Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#,
131 {
132 fn clonerust-analyzer cargo itertools 0.14.0 format/impl#[`FormatWith<'_, I, F>`][Clone]clone().(&self) -> Selfrust-analyzer cargo itertools 0.14.0 format/impl#[`FormatWith<'_, I, F>`][Clone] {
133 struct PutBackOnDroprust-analyzer cargo itertools 0.14.0 format/PutBackOnDrop#<'r, 'a, I, F> {
134 intorust-analyzer cargo itertools 0.14.0 format/PutBackOnDrop#into.: &'r FormatWithrust-analyzer cargo itertools 0.14.0 format/FormatWith#<'a, I, F>,
135 innerrust-analyzer cargo itertools 0.14.0 format/PutBackOnDrop#inner.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(I, F)>,
136 }
137 // This ensures we preserve the state of the original `FormatWith` if `Clone` panics
138 impl<I, F> Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for PutBackOnDroprust-analyzer cargo itertools 0.14.0 format/PutBackOnDrop#<'_, '_, I, F> {
139 fn droprust-analyzer cargo itertools 0.14.0 format/impl#[`PutBackOnDrop<'_, '_, I, F>`][Drop]drop().(&mut self) {
140 self.intorust-analyzer cargo itertools 0.14.0 format/PutBackOnDrop#into..innerrust-analyzer cargo itertools 0.14.0 format/FormatWith#inner..setrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]set().(self.innerrust-analyzer cargo itertools 0.14.0 format/PutBackOnDrop#inner..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().())
141 }
142 }
143 let pbod = PutBackOnDroprust-analyzer cargo itertools 0.14.0 format/PutBackOnDrop# {
144 innerrust-analyzer cargo itertools 0.14.0 format/PutBackOnDrop#inner.: self.innerrust-analyzer cargo itertools 0.14.0 format/FormatWith#inner..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]take().(),
145 intorust-analyzer cargo itertools 0.14.0 format/PutBackOnDrop#into.: self,
146 };
147 Selfrust-analyzer cargo itertools 0.14.0 format/impl#[`FormatWith<'_, I, F>`][Clone] {
148 innerrust-analyzer cargo itertools 0.14.0 format/FormatWith#inner.: Cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/Cell#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]new().(pbod.innerrust-analyzer cargo itertools 0.14.0 format/PutBackOnDrop#inner..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Clone]clone().()),
149 seprust-analyzer cargo itertools 0.14.0 format/FormatWith#sep.: self.seprust-analyzer cargo itertools 0.14.0 format/FormatWith#sep.,
150 }
151 }
152 }
153
154 impl<I> Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# for Formatrust-analyzer cargo itertools 0.14.0 format/Format#<'_, I>
155 where
156 I: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#,
157 {
158 fn clonerust-analyzer cargo itertools 0.14.0 format/impl#[`Format<'_, I>`][Clone]clone().(&self) -> Selfrust-analyzer cargo itertools 0.14.0 format/impl#[`Format<'_, I>`][Clone] {
159 struct PutBackOnDroprust-analyzer cargo itertools 0.14.0 format/PutBackOnDrop#<'r, 'a, I> {
160 intorust-analyzer cargo itertools 0.14.0 format/PutBackOnDrop#into.: &'r Formatrust-analyzer cargo itertools 0.14.0 format/Format#<'a, I>,
161 innerrust-analyzer cargo itertools 0.14.0 format/PutBackOnDrop#inner.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<I>,
162 }
163 // This ensures we preserve the state of the original `FormatWith` if `Clone` panics
164 impl<I> Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for PutBackOnDroprust-analyzer cargo itertools 0.14.0 format/PutBackOnDrop#<'_, '_, I> {
165 fn droprust-analyzer cargo itertools 0.14.0 format/impl#[`PutBackOnDrop<'_, '_, I>`][Drop]drop().(&mut self) {
166 self.intorust-analyzer cargo itertools 0.14.0 format/PutBackOnDrop#into..innerrust-analyzer cargo itertools 0.14.0 format/Format#inner..setrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]set().(self.innerrust-analyzer cargo itertools 0.14.0 format/PutBackOnDrop#inner..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().())
167 }
168 }
169 let pbod = PutBackOnDroprust-analyzer cargo itertools 0.14.0 format/PutBackOnDrop# {
170 innerrust-analyzer cargo itertools 0.14.0 format/PutBackOnDrop#inner.: self.innerrust-analyzer cargo itertools 0.14.0 format/Format#inner..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]take().(),
171 intorust-analyzer cargo itertools 0.14.0 format/PutBackOnDrop#into.: self,
172 };
173 Selfrust-analyzer cargo itertools 0.14.0 format/impl#[`Format<'_, I>`][Clone] {
174 innerrust-analyzer cargo itertools 0.14.0 format/Format#inner.: Cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/Cell#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]new().(pbod.innerrust-analyzer cargo itertools 0.14.0 format/PutBackOnDrop#inner..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Clone]clone().()),
175 seprust-analyzer cargo itertools 0.14.0 format/Format#sep.: self.seprust-analyzer cargo itertools 0.14.0 format/Format#sep.,
176 }
177 }
178 }