1use {
5 crate::{
6 expr::without_block::path::{GenericArgs, PathIdentSegment, TypePathFn},
7 token,
8 },
9 rustidy_ast_util::{Punctuated, punct},
10 rustidy_format::{Format, Formattable, WhitespaceFormat},
11 rustidy_parse::Parse,
12 rustidy_print::Print,
13 rustidy_util::Whitespace,
14};
15
16#[derive(PartialEq, Eq, Clone, Debug)]
18#[derive(serde::Serialize, serde::Deserialize)]
19#[derive(Parse, Formattable, Format, Print)]
20pub struct TypePath {
21 pub prefix: Option<token::PathSep>,
22 #[format(prefix_ws(expr = Whitespace::REMOVE, if_ = self.prefix.is_some()))]
23 #[format(args = punct::fmt(Whitespace::REMOVE, Whitespace::REMOVE))]
24 pub segments: Punctuated<TypePathSegment, token::PathSep>,
25}
26
27#[derive(PartialEq, Eq, Clone, Debug)]
29#[derive(serde::Serialize, serde::Deserialize)]
30#[derive(Parse, Formattable, Format, Print)]
31pub struct TypePathSegment {
32 pub path: PathIdentSegment,
33 #[format(prefix_ws = Whitespace::REMOVE)]
34 pub generics: Option<TypePathSegmentGenerics>,
35}
36
37#[derive(PartialEq, Eq, Clone, Debug)]
38#[derive(serde::Serialize, serde::Deserialize)]
39#[derive(Parse, Formattable, Format, Print)]
40pub struct TypePathSegmentGenerics {
41 pub sep: Option<token::PathSep>,
42 #[format(prefix_ws(expr = Whitespace::REMOVE, if_ = self.sep.is_some()))]
43 pub inner: GenericArgsOrTypePathFn,
44}
45
46#[derive(PartialEq, Eq, Clone, Debug)]
47#[derive(serde::Serialize, serde::Deserialize)]
48#[derive(Parse, Formattable, Format, Print)]
49pub enum GenericArgsOrTypePathFn {
50 GenericArgs(GenericArgs),
51 TypePathFn(TypePathFn),
52}