Debian Codegraph @

src/util.rs

raw symbols SCIP
1 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/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#;
2
3 use proc_macro2rust-analyzer cargo proc-macro2 1.0.93 crate/::Spanrust-analyzer cargo proc-macro2 1.0.93 Span#;
4 use synrust-analyzer cargo syn 2.0.96 crate/::Typerust-analyzer cargo syn 2.0.96 ty/Type#;
5
6 // https://stackoverflow.com/questions/55271857/how-can-i-get-the-t-from-an-optiont-when-using-syn
7 pub(craterust-analyzer cargo lofty_attr 0.11.1 crate/) fn extract_type_from_optionrust-analyzer cargo lofty_attr 0.11.1 util/extract_type_from_option().(ty: &Typerust-analyzer cargo syn 2.0.96 ty/Type#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Typerust-analyzer cargo syn 2.0.96 ty/Type#> {
8 use synrust-analyzer cargo syn 2.0.96 crate/::{GenericArgumentrust-analyzer cargo syn 2.0.96 path/GenericArgument#, Pathrust-analyzer cargo syn 2.0.96 path/Path#, PathArgumentsrust-analyzer cargo syn 2.0.96 path/PathArguments#, PathSegmentrust-analyzer cargo syn 2.0.96 path/PathSegment#};
9
10 fn extract_type_pathrust-analyzer cargo lofty_attr 0.11.1 util/extract_type_path().(ty: &Typerust-analyzer cargo syn 2.0.96 ty/Type#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&Pathrust-analyzer cargo syn 2.0.96 path/Path#> {
11 match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().ty {
12 Typerust-analyzer cargo syn 2.0.96 ty/Type#::Pathrust-analyzer cargo syn 2.0.96 ty/Type#Path#(ref typepath) if typepath.qselfrust-analyzer cargo syn 2.0.96 ty/TypePath#qself..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&typepath.pathrust-analyzer cargo syn 2.0.96 ty/TypePath#path.),
13 _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
14 }
15 }
16
17 fn extract_option_segmentrust-analyzer cargo lofty_attr 0.11.1 util/extract_option_segment().(path: &Pathrust-analyzer cargo syn 2.0.96 path/Path#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&PathSegmentrust-analyzer cargo syn 2.0.96 path/PathSegment#> {
18 let idents_of_path = path.segmentsrust-analyzer cargo syn 2.0.96 path/Path#segments..iterrust-analyzer cargo syn 2.0.96 punctuated/impl#[`Punctuated<T, P>`]iter().().foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#fold().(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(), |mut acc, v| {
19 acc.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(&v.identrust-analyzer cargo syn 2.0.96 path/PathSegment#ident..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
20 acc.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('|');
21 acc
22 });
23 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["Option|", "std|option|Option|", "core|option|Option|"]
24 .into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().()
25 .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#find().(|s| idents_of_path 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().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().s)
26 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|_| path.segmentsrust-analyzer cargo syn 2.0.96 path/Path#segments..lastrust-analyzer cargo syn 2.0.96 punctuated/impl#[`Punctuated<T, P>`]last().())
27 }
28
29 extract_type_pathrust-analyzer cargo lofty_attr 0.11.1 util/extract_type_path().(ty)
30 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(extract_option_segmentrust-analyzer cargo lofty_attr 0.11.1 util/extract_option_segment().)
31 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|path_seg| {
32 let type_params = &path_seg.argumentsrust-analyzer cargo syn 2.0.96 path/PathSegment#arguments.;
33 // It should have only on angle-bracketed param ("<String>"):
34 match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().type_params {
35 PathArgumentsrust-analyzer cargo syn 2.0.96 path/PathArguments#::AngleBracketedrust-analyzer cargo syn 2.0.96 path/PathArguments#AngleBracketed#(ref params) => params.argsrust-analyzer cargo syn 2.0.96 path/AngleBracketedGenericArguments#args..firstrust-analyzer cargo syn 2.0.96 punctuated/impl#[`Punctuated<T, P>`]first().(),
36 _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
37 }
38 })
39 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|generic_arg| match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().generic_arg {
40 GenericArgumentrust-analyzer cargo syn 2.0.96 path/GenericArgument#::Typerust-analyzer cargo syn 2.0.96 path/GenericArgument#Type#(ref ty) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ty.clonerust-analyzer cargo syn 2.0.96 gen/clone/impl#[`crate::Type`][Clone]clone().()),
41 _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
42 })
43 }
44
45 pub(craterust-analyzer cargo lofty_attr 0.11.1 crate/) fn errrust-analyzer cargo lofty_attr 0.11.1 util/err().<T: Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#>(span: Spanrust-analyzer cargo proc-macro2 1.0.93 Span#, error: T) -> synrust-analyzer cargo syn 2.0.96 crate/::Errorrust-analyzer cargo syn 2.0.96 error/Error# {
46 synrust-analyzer cargo syn 2.0.96 crate/::Errorrust-analyzer cargo syn 2.0.96 error/Error#::newrust-analyzer cargo syn 2.0.96 error/impl#[Error]new().(span, error)
47 }