Debian Codegraph @

src/iteratom.rs

raw symbols SCIP
1 // (c) 2017 Productize SPRL <[email protected]>
2
3 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::Peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/Peekable#;
4 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/::Iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/Iter#;
5
6 use Sexprust-analyzer cargo symbolic_expressions 5.0.3 sexp/Sexp#;
7 use error::SexpError;
8
9 /// convert an `&Sexp` to something
10 pub trait FromSexprust-analyzer cargo symbolic_expressions 5.0.3 iteratom/FromSexp#
11 where
12 Self: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#,
13 {
14 /// convert from a symbolic-expression to something
15 fn from_sexprust-analyzer cargo symbolic_expressions 5.0.3 iteratom/FromSexp#from_sexp().(&Sexp) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Self, SexpErrorrust-analyzer cargo symbolic_expressions 5.0.3 error/SexpError#>;
16 }
17
18 /// convert from a symbolic-expression to something (dispatcher)
19 pub fn from_sexprust-analyzer cargo symbolic_expressions 5.0.3 iteratom/from_sexp().<T: FromSexprust-analyzer cargo symbolic_expressions 5.0.3 iteratom/FromSexp#>(s: &Sexprust-analyzer cargo symbolic_expressions 5.0.3 sexp/Sexp#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, SexpErrorrust-analyzer cargo symbolic_expressions 5.0.3 error/SexpError#> {
20 T::from_sexprust-analyzer cargo symbolic_expressions 5.0.3 iteratom/FromSexp#from_sexp().(s)
21 }
22
23 /// Atom iterator wrapper
24 pub struct IterAtomrust-analyzer cargo symbolic_expressions 5.0.3 iteratom/IterAtom#<'a> {
25 namerust-analyzer cargo symbolic_expressions 5.0.3 iteratom/IterAtom#name.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
26 /// containing iterable (pub for now)
27 pub iterrust-analyzer cargo symbolic_expressions 5.0.3 iteratom/IterAtom#iter.: Peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/Peekable#<Iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/Iter#<'a, Sexprust-analyzer cargo symbolic_expressions 5.0.3 sexp/Sexp#>>,
28 }
29
30
31 impl<'a> IterAtomrust-analyzer cargo symbolic_expressions 5.0.3 iteratom/IterAtom#<'a> {
32 /// deconstruct a `Sexp` that is a list and starts with 'name'
33 pub fn newrust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]new().(s: &'a Sexprust-analyzer cargo symbolic_expressions 5.0.3 sexp/Sexp#, name: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<IterAtomrust-analyzer cargo symbolic_expressions 5.0.3 iteratom/IterAtom#<'a>, SexpErrorrust-analyzer cargo symbolic_expressions 5.0.3 error/SexpError#> {
34 let v = s.listrust-analyzer cargo symbolic_expressions 5.0.3 sexp/impl#[Sexp]list().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
35 let mut i = v.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().();
36 let st = match i.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]next().() {
37 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("missing first element {} in list {}", name, s).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()),
38 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(e) => e.stringrust-analyzer cargo symbolic_expressions 5.0.3 sexp/impl#[Sexp]string().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
39 };
40 if st rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().name {
41 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("list {} doesn't start with {}, but with {}", s, name, st).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
42 }
43 let i = i.peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#peekable().();
44 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(IterAtomrust-analyzer cargo symbolic_expressions 5.0.3 iteratom/IterAtom# {
45 namerust-analyzer cargo symbolic_expressions 5.0.3 iteratom/IterAtom#name.: name.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
46 iterrust-analyzer cargo symbolic_expressions 5.0.3 iteratom/IterAtom#iter.: i,
47 })
48 }
49
50 /// deconstruct a `Sexp` that is a list and doesn't start with a name
51 pub fn new_namelessrust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]new_nameless().(s: &'a Sexprust-analyzer cargo symbolic_expressions 5.0.3 sexp/Sexp#, name: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<IterAtomrust-analyzer cargo symbolic_expressions 5.0.3 iteratom/IterAtom#<'a>, SexpErrorrust-analyzer cargo symbolic_expressions 5.0.3 error/SexpError#> {
52 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(IterAtomrust-analyzer cargo symbolic_expressions 5.0.3 iteratom/IterAtom# {
53 namerust-analyzer cargo symbolic_expressions 5.0.3 iteratom/IterAtom#name.: name.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
54 iterrust-analyzer cargo symbolic_expressions 5.0.3 iteratom/IterAtom#iter.: s.listrust-analyzer cargo symbolic_expressions 5.0.3 sexp/impl#[Sexp]list().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#peekable().(),
55 })
56 }
57
58 /// expect a named field, retrieved by `get`
59 fn expectrust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]expect().<T, F>(&mut self, name: &str, get: F) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, SexpErrorrust-analyzer cargo symbolic_expressions 5.0.3 error/SexpError#>
60 where
61 F: Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&Sexprust-analyzer cargo symbolic_expressions 5.0.3 sexp/Sexp#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, SexpErrorrust-analyzer cargo symbolic_expressions 5.0.3 error/SexpError#>,
62 {
63 match self.iterrust-analyzer cargo symbolic_expressions 5.0.3 iteratom/IterAtom#iter..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().() {
64 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(x) => get(x),
65 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("missing {} field in {}", name, self.namerust-analyzer cargo symbolic_expressions 5.0.3 iteratom/IterAtom#name.).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()),
66 }
67 }
68
69 /// expect an integer while iterating a `Sexp` list
70 ///
71 /// shape: (... ... 42 ...)
72 pub fn irust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]i().(&mut self, name: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<i64, SexpErrorrust-analyzer cargo symbolic_expressions 5.0.3 error/SexpError#> {
73 self.expectrust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]expect().(name, |x| x.irust-analyzer cargo symbolic_expressions 5.0.3 sexp/impl#[Sexp]i().().map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`From<Self>`]from().))
74 }
75
76 /// expect a float while iterating a `Sexp` list
77 ///
78 /// shape: (... ... 42.7 ...)
79 pub fn frust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]f().(&mut self, name: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<f64, SexpErrorrust-analyzer cargo symbolic_expressions 5.0.3 error/SexpError#> {
80 self.expectrust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]expect().(name, |x| x.frust-analyzer cargo symbolic_expressions 5.0.3 sexp/impl#[Sexp]f().().map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`From<Self>`]from().))
81 }
82
83 /// expect a String while iterating a `Sexp` list
84 ///
85 /// shape: (... ... hello ...)
86 pub fn srust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]s().(&mut self, name: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, SexpErrorrust-analyzer cargo symbolic_expressions 5.0.3 error/SexpError#> {
87 self.expectrust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]expect().(name, |x| x.srust-analyzer cargo symbolic_expressions 5.0.3 sexp/impl#[Sexp]s().().map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`From<Self>`]from().))
88 }
89
90 /// expect a list contained String while iterating a `Sexp` list
91 ///
92 /// shape: (... ... hello ...)
93 pub fn s_in_listrust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]s_in_list().(&mut self, name: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, SexpErrorrust-analyzer cargo symbolic_expressions 5.0.3 error/SexpError#> {
94 self.expectrust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]expect().(name, |x| x.named_value_srust-analyzer cargo symbolic_expressions 5.0.3 sexp/impl#[Sexp]named_value_s().(name).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`From<Self>`]from().))
95 }
96
97 /// expect a list contained i64 while iterating a `Sexp` list
98 ///
99 /// shape: (... ... (name 42) ...)
100 pub fn i_in_listrust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]i_in_list().(&mut self, name: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<i64, SexpErrorrust-analyzer cargo symbolic_expressions 5.0.3 error/SexpError#> {
101 self.expectrust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]expect().(name, |x| x.named_value_irust-analyzer cargo symbolic_expressions 5.0.3 sexp/impl#[Sexp]named_value_i().(name).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`From<Self>`]from().))
102 }
103
104 /// expect a list contained f64 while iterating a `Sexp` list
105 ///
106 /// shape: (... ... (name 42.7) ...)
107 pub fn f_in_listrust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]f_in_list().(&mut self, name: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<f64, SexpErrorrust-analyzer cargo symbolic_expressions 5.0.3 error/SexpError#> {
108 self.expectrust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]expect().(name, |x| x.named_value_frust-analyzer cargo symbolic_expressions 5.0.3 sexp/impl#[Sexp]named_value_f().(name).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`From<Self>`]from().))
109 }
110
111
112 /// expect a `Sexp` while iterating a `Sexp` list
113 ///
114 /// shape: (... ... (...) ...)
115 pub fn trust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]t().<T: FromSexprust-analyzer cargo symbolic_expressions 5.0.3 iteratom/FromSexp#>(&mut self, name: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, SexpErrorrust-analyzer cargo symbolic_expressions 5.0.3 error/SexpError#> {
116 self.expectrust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]expect().(name, |x| T::from_sexprust-analyzer cargo symbolic_expressions 5.0.3 iteratom/FromSexp#from_sexp().(x))
117 }
118
119 /// expect a list containing a `Sexp` while iterating a `Sexp` list
120 ///
121 /// shape: (... ... (name (...)) ...)
122 pub fn t_in_listrust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]t_in_list().<T: FromSexprust-analyzer cargo symbolic_expressions 5.0.3 iteratom/FromSexp#>(&mut self, name: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, SexpErrorrust-analyzer cargo symbolic_expressions 5.0.3 error/SexpError#> {
123 self.expectrust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]expect().(name, |x| T::from_sexprust-analyzer cargo symbolic_expressions 5.0.3 iteratom/FromSexp#from_sexp().(x.named_valuerust-analyzer cargo symbolic_expressions 5.0.3 sexp/impl#[Sexp]named_value().(name)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().))
124 }
125
126 /// expect remainder of iterator to be a `Vec<T>`
127 ///
128 /// shape: (... T T T)
129 pub fn vecrust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]vec().<T: FromSexprust-analyzer cargo symbolic_expressions 5.0.3 iteratom/FromSexp#>(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<T>, SexpErrorrust-analyzer cargo symbolic_expressions 5.0.3 error/SexpError#> {
130 let mut res = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
131 loop {
132 match self.iterrust-analyzer cargo symbolic_expressions 5.0.3 iteratom/IterAtom#iter..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().() {
133 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => break,
134 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(e) => {
135 let p = from_sexprust-analyzer cargo symbolic_expressions 5.0.3 iteratom/from_sexp().(e)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
136 res.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(p);
137 }
138 }
139 }
140 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(res)
141 }
142
143 /// maybe something while iterating a `Sexp` list
144 /// returns `None` when the `convert` function fails
145 fn mayberust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]maybe().<X, F>(&mut self, convert: F) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<X>
146 where
147 F: Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&Sexprust-analyzer cargo symbolic_expressions 5.0.3 sexp/Sexp#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<X, SexpErrorrust-analyzer cargo symbolic_expressions 5.0.3 error/SexpError#>,
148 {
149 let res = match self.iterrust-analyzer cargo symbolic_expressions 5.0.3 iteratom/IterAtom#iter..peekrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]peek().() {
150 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
151 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(s) => match convert(s) {
152 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(t) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(t),
153 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
154 },
155 };
156 match res {
157 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(x) => {
158 let _ = self.iterrust-analyzer cargo symbolic_expressions 5.0.3 iteratom/IterAtom#iter..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().();
159 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(x)
160 }
161 x => x,
162 }
163 }
164
165 /// maybe a `FromSexp` while iterating a `Sexp` list
166 ///
167 /// shape: (... ... (...) ...)
168 pub fn maybe_trust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]maybe_t().<T: FromSexprust-analyzer cargo symbolic_expressions 5.0.3 iteratom/FromSexp#>(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T> {
169 self.mayberust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]maybe().(|x| T::from_sexprust-analyzer cargo symbolic_expressions 5.0.3 iteratom/FromSexp#from_sexp().(x))
170 }
171
172 /// maybe a `String` while iterating a `Sexp` list
173 ///
174 /// shape: (... ... hello ...)
175 pub fn maybe_srust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]maybe_s().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
176 self.mayberust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]maybe().(|x| x.srust-analyzer cargo symbolic_expressions 5.0.3 sexp/impl#[Sexp]s().())
177 }
178
179 /// maybe a `String` while iterating a `Sexp` list
180 ///
181 /// shape: (... ... literal ...)
182 pub fn maybe_literal_srust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]maybe_literal_s().(&mut self, l: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
183 self.mayberust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]maybe().(|x| {
184 let z = x.srust-analyzer cargo symbolic_expressions 5.0.3 sexp/impl#[Sexp]s().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
185 if z rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().l {
186 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(z)
187 } else {
188 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#("unexpected".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())
189 }
190 })
191 }
192
193 /// maybe an `i64` while iterating a `Sexp` list
194 ///
195 /// shape: (... ... 42 ...)
196 pub fn maybe_irust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]maybe_i().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<i64> {
197 self.mayberust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]maybe().(|x| x.irust-analyzer cargo symbolic_expressions 5.0.3 sexp/impl#[Sexp]i().())
198 }
199
200 /// maybe an `f64` while iterating a `Sexp` list
201 ///
202 /// shape: (... ... 42.7 ...)
203 pub fn maybe_frust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]maybe_f().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<f64> {
204 self.mayberust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]maybe().(|x| x.frust-analyzer cargo symbolic_expressions 5.0.3 sexp/impl#[Sexp]f().())
205 }
206
207 /// maybe a list containing a `String` while iterating a `Sexp` list
208 ///
209 /// shape: (... ... (name hello) ...)
210 pub fn maybe_s_in_listrust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]maybe_s_in_list().(&mut self, name: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
211 self.mayberust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]maybe().(|x| x.named_value_srust-analyzer cargo symbolic_expressions 5.0.3 sexp/impl#[Sexp]named_value_s().(name))
212 }
213
214 /// maybe a list containing an `i64` while iterating a `Sexp` list
215 ///
216 /// shape: (... ... (name 42) ...)
217 pub fn maybe_i_in_listrust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]maybe_i_in_list().(&mut self, name: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<i64> {
218 self.mayberust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]maybe().(|x| x.named_value_irust-analyzer cargo symbolic_expressions 5.0.3 sexp/impl#[Sexp]named_value_i().(name))
219 }
220
221 /// maybe a list containing an `f64` while iterating a `Sexp` list
222 ///
223 /// shape: (... ... (name 42.7) ...)
224 pub fn maybe_f_in_listrust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]maybe_f_in_list().(&mut self, name: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<f64> {
225 self.mayberust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]maybe().(|x| x.named_value_frust-analyzer cargo symbolic_expressions 5.0.3 sexp/impl#[Sexp]named_value_f().(name))
226 }
227
228 /// make sure we consumed all of the iterator
229 ///
230 /// shape: )
231 pub fn closerust-analyzer cargo symbolic_expressions 5.0.3 iteratom/impl#[`IterAtom<'a>`]close().<T>(&mut self, x: T) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, SexpErrorrust-analyzer cargo symbolic_expressions 5.0.3 error/SexpError#> {
232 match self.iterrust-analyzer cargo symbolic_expressions 5.0.3 iteratom/IterAtom#iter..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().() {
233 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(x) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Unexpected {} in {}", x, self.namerust-analyzer cargo symbolic_expressions 5.0.3 iteratom/IterAtom#name.).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()),
234 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(x),
235 }
236 }
237 }