1use serde::{Deserialize, Serialize};
2
3pub mod parse;
4
5#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
6pub struct Item {
7 pub path: Vec<String>,
8 pub link: Vec<String>,
9 pub docs: Option<String>,
10}
11
12#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
13pub struct Query {
14 pub name: Option<Symbol>,
15 pub kind: Option<QueryKind>,
16}
17
18impl Query {
19 pub fn args(&self) -> Option<Vec<Argument>> {
20 self.kind
21 .as_ref()
22 .map(|kind| {
23 let QueryKind::FunctionQuery(f) = kind;
24 &f.decl
25 })
26 .and_then(|decl| decl.inputs.clone())
27 }
28}
29
30#[non_exhaustive]
31#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
32pub enum QueryKind {
33 FunctionQuery(Function),
34}
35
36#[non_exhaustive]
37#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
38pub struct Function {
39 pub decl: FnDecl,
40 }
42
43#[non_exhaustive]
44#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
45pub enum GenericArgs {
46 AngleBracketed {
47 args: Vec<Option<GenericArg>>, },
49 }
51
52#[non_exhaustive]
53#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
54pub enum GenericArg {
55 Type(Type),
57 }
59#[non_exhaustive]
60#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
61pub struct FnDecl {
62 pub inputs: Option<Vec<Argument>>,
63 pub output: Option<FnRetTy>,
64 }
66
67#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
68pub struct Argument {
69 pub ty: Option<Type>,
70 pub name: Option<Symbol>,
71}
72
73#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
74pub enum FnRetTy {
75 Return(Type),
76 DefaultReturn,
77}
78
79pub type Symbol = String;
80
81#[non_exhaustive]
82#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
83pub enum Type {
84 UnresolvedPath {
86 name: Symbol,
87 args: Option<Box<GenericArgs>>,
88 },
89 Generic(String),
90 Primitive(PrimitiveType),
91 Tuple(Vec<Option<Type>>),
92 Slice(Option<Box<Type>>),
93 Never,
94 RawPointer {
95 mutable: bool,
96 type_: Box<Type>,
97 },
98 BorrowedRef {
99 mutable: bool,
100 type_: Box<Type>,
101 },
102}
103
104impl Type {
105 pub fn inner_type(&self) -> &Self {
106 match self {
107 Type::RawPointer { type_, .. } => type_.inner_type(),
108 Type::BorrowedRef { type_, .. } => type_.inner_type(),
109 _ => self,
110 }
111 }
112}
113
114#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
117pub enum PrimitiveType {
118 Isize,
119 I8,
120 I16,
121 I32,
122 I64,
123 I128,
124 Usize,
125 U8,
126 U16,
127 U32,
128 U64,
129 U128,
130 F32,
131 F64,
132 Char,
133 Bool,
134 Str,
135 Unit,
136 Never,
137}
138
139impl PrimitiveType {
140 pub fn as_str(&self) -> &str {
141 use PrimitiveType::*;
142 match self {
143 Isize => "isize",
144 I8 => "i8",
145 I16 => "i16",
146 I32 => "i32",
147 I64 => "i64",
148 I128 => "i128",
149 Usize => "usize",
150 U8 => "u8",
151 U16 => "u16",
152 U32 => "u32",
153 U64 => "u64",
154 U128 => "u128",
155 F32 => "f32",
156 F64 => "f64",
157 Char => "char",
158 Bool => "bool",
159 Str => "str",
160 Unit => "unit",
161 Never => "never",
162 }
163 }
164}