MCPcopy Create free account
hub / github.com/csskit/csskit / atom_parse_if_peek

Method atom_parse_if_peek

crates/csskit_derives/src/parse.rs:149–162  ·  view source on GitHub ↗

Emits a simple parse-if-peek for a single atom field.

(&self)

Source from the content-addressed store, hash-verified

147
148 /// Emits a simple parse-if-peek for a single atom field.
149 fn atom_parse_if_peek(&self) -> TokenStream {
150 let atom = self.atom.as_ref().expect("atom_parse_if_peek called without atom");
151 let atom_path = atom.path();
152 let atom_set = atom.first_segment();
153 let var = &self.var;
154 let inner_ty = self.ty.unpack_option();
155 quote! {
156 if p.peek::<#inner_ty>()
157 && p.to_atom::<#atom_set>(c) == #atom_path
158 {
159 #var = Some(p.parse::<#inner_ty>()?);
160 }
161 }
162 }
163
164 fn binding(&self) -> TokenStream {
165 let Field { var, ty, .. } = self;

Callers 1

hoisted_preloopMethod · 0.80

Calls 4

as_refMethod · 0.80
pathMethod · 0.80
first_segmentMethod · 0.80
unpack_optionMethod · 0.80

Tested by

no test coverage detected