xref: /third_party/rust/crates/serde/serde_derive/src/this.rs (revision 7e2e9c0c)
  • Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/rust/crates/serde/serde_derive/src/
1use crate::internals::ast::Container;
2use syn::{Path, PathArguments, Token};
3
4pub fn this_type(cont: &Container) -> Path {
5    if let Some(remote) = cont.attrs.remote() {
6        let mut this = remote.clone();
7        for segment in &mut this.segments {
8            if let PathArguments::AngleBracketed(arguments) = &mut segment.arguments {
9                arguments.colon2_token = None;
10            }
11        }
12        this
13    } else {
14        Path::from(cont.ident.clone())
15    }
16}
17
18pub fn this_value(cont: &Container) -> Path {
19    if let Some(remote) = cont.attrs.remote() {
20        let mut this = remote.clone();
21        for segment in &mut this.segments {
22            if let PathArguments::AngleBracketed(arguments) = &mut segment.arguments {
23                if arguments.colon2_token.is_none() {
24                    arguments.colon2_token = Some(Token![::](arguments.lt_token.span));
25                }
26            }
27        }
28        this
29    } else {
30        Path::from(cont.ident.clone())
31    }
32}
33

Indexes created Thu Nov 07 10:32:03 CST 2024