Debian Codegraph @

src/inflate.rs

raw symbols SCIP
1 // Copyright (c) Meta Platforms, Inc. and affiliates.
2 //
3 // This source code is licensed under the MIT license found in the
4 // LICENSE file in the root directory of this source tree
5
6 use proc_macrorust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro crate/::TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#;
7 use quoterust-analyzer cargo quote 1.0.40 crate/::{format_identrust-analyzer cargo quote 1.0.40 format/format_ident!, quoterust-analyzer cargo quote 1.0.40 quote!, quote_spannedrust-analyzer cargo quote 1.0.40 quote_spanned!};
8 use synrust-analyzer cargo syn 2.0.101 crate/::{selfrust-analyzer cargo syn 2.0.101 crate/, spannedrust-analyzer cargo syn 2.0.101 spanned/::Spannedrust-analyzer cargo syn 2.0.101 spanned/Spanned#, Datarust-analyzer cargo syn 2.0.101 derive/Data#, DataEnumrust-analyzer cargo syn 2.0.101 derive/DataEnum#, DeriveInputrust-analyzer cargo syn 2.0.101 derive/DeriveInput#, Fieldsrust-analyzer cargo syn 2.0.101 data/Fields#, FieldsUnnamedrust-analyzer cargo syn 2.0.101 data/FieldsUnnamed#};
9
10 pub(craterust-analyzer cargo libcst_derive 1.8.6 crate/) fn impl_inflaterust-analyzer cargo libcst_derive 1.8.6 inflate/impl_inflate().(ast: &DeriveInputrust-analyzer cargo syn 2.0.101 derive/DeriveInput#) -> TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream# {
11 match &ast.datarust-analyzer cargo syn 2.0.101 derive/DeriveInput#data. {
12 Datarust-analyzer cargo syn 2.0.101 derive/Data#::Enumrust-analyzer cargo syn 2.0.101 derive/Data#Enum#(e) => impl_inflate_enumrust-analyzer cargo libcst_derive 1.8.6 inflate/impl_inflate_enum().(ast, e),
13 Datarust-analyzer cargo syn 2.0.101 derive/Data#::Structrust-analyzer cargo syn 2.0.101 derive/Data#Struct#(s) => quote_spannedrust-analyzer cargo quote 1.0.40 quote_spanned!! {
14 s.struct_tokenrust-analyzer cargo syn 2.0.101 derive/DataStruct#struct_token..spanrust-analyzer cargo syn 2.0.101 spanned/impl#[T][Spanned]span().() =>
15 compile_error!("Struct type is not supported")
16 }
17 .intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
18 Datarust-analyzer cargo syn 2.0.101 derive/Data#::Unionrust-analyzer cargo syn 2.0.101 derive/Data#Union#(u) => quote_spannedrust-analyzer cargo quote 1.0.40 quote_spanned!! {
19 u.union_tokenrust-analyzer cargo syn 2.0.101 derive/DataUnion#union_token..spanrust-analyzer cargo syn 2.0.101 spanned/impl#[T][Spanned]span().() =>
20 compile_error!("Union type is not supported")
21 }
22 .intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
23 }
24 }
25
26 fn impl_inflate_enumrust-analyzer cargo libcst_derive 1.8.6 inflate/impl_inflate_enum().(ast: &DeriveInputrust-analyzer cargo syn 2.0.101 derive/DeriveInput#, e: &DataEnumrust-analyzer cargo syn 2.0.101 derive/DataEnum#) -> TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream# {
27 let mut varnames = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![];
28 for var in e.variantsrust-analyzer cargo syn 2.0.101 derive/DataEnum#variants..iterrust-analyzer cargo syn 2.0.101 punctuated/impl#[`Punctuated<T, P>`]iter().() {
29 match &var.fieldsrust-analyzer cargo syn 2.0.101 data/Variant#fields. {
30 Fieldsrust-analyzer cargo syn 2.0.101 data/Fields#::Namedrust-analyzer cargo syn 2.0.101 data/Fields#Named#(n) => {
31 return quote_spannedrust-analyzer cargo quote 1.0.40 quote_spanned!! {
32 n.spanrust-analyzer cargo syn 2.0.101 spanned/impl#[T][Spanned]span().() =>
33 compile_error!("Named enum fields not supported")
34 }
35 .intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()
36 }
37 f @ Fieldsrust-analyzer cargo syn 2.0.101 data/Fields#::Unitrust-analyzer cargo syn 2.0.101 data/Fields#Unit# => {
38 return quote_spannedrust-analyzer cargo quote 1.0.40 quote_spanned!! {
39 f.spanrust-analyzer cargo syn 2.0.101 spanned/impl#[T][Spanned]span().() =>
40 compile_error!("Empty enum variants not supported")
41 }
42 .intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()
43 }
44 Fieldsrust-analyzer cargo syn 2.0.101 data/Fields#::Unnamedrust-analyzer cargo syn 2.0.101 data/Fields#Unnamed#(FieldsUnnamedrust-analyzer cargo syn 2.0.101 data/FieldsUnnamed# { unnamedrust-analyzer cargo syn 2.0.101 data/FieldsUnnamed#unnamed., .. }) => {
45 if unnamed.lenrust-analyzer cargo syn 2.0.101 punctuated/impl#[`Punctuated<T, P>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().1 {
46 return quote_spannedrust-analyzer cargo quote 1.0.40 quote_spanned!! {
47 unnamed.spanrust-analyzer cargo syn 2.0.101 spanned/impl#[T][Spanned]span().() =>
48 compile_error!("Multiple unnamed fields not supported")
49 }
50 .intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().();
51 }
52 varnames.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(&var.identrust-analyzer cargo syn 2.0.101 data/Variant#ident.);
53 }
54 }
55 }
56 let ident = &ast.identrust-analyzer cargo syn 2.0.101 derive/DeriveInput#ident.;
57 let generics = &ast.genericsrust-analyzer cargo syn 2.0.101 derive/DeriveInput#generics.;
58 let ident_str = ident.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
59 let inflated_ident = format_identrust-analyzer cargo quote 1.0.40 format/format_ident!!(
60 "{}",
61 ident_str
62 .strip_prefixrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]strip_prefix().("Deflated")
63 .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Cannot implement Inflate on a non-Deflated item")
64 );
65 let gen = quoterust-analyzer cargo quote 1.0.40 quote!! {
66 impl#generics Inflate<'a> for #ident #generics {
67 type Inflated = #inflated_ident <'a>;
68 fn inflate(mut self, config: & crate::tokenizer::whitespace_parser::Config<'a>) -> std::result::Result<Self::Inflated, crate::tokenizer::whitespace_parser::WhitespaceError> {
69 match self {
70 #(Self::#varnames(x) => Ok(Self::Inflated::#varnames(x.inflate(config)?)),)*
71 }
72 }
73 }
74 };
75 gen.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()
76 }