1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use super::source::{ImportString, ImportType};
use crate::common::{ModuleId, ModuleName, RelativeModulePath};
use empty_type::{Container, Empty, EmptyType};
use serde::{Deserialize, Deserializer};
use std::borrow::{BorrowMut, Cow};
#[derive(Debug)]
pub enum Reason<'a> {
Imported(ImportedReason<'a>),
Entry,
}
impl<'de: 'a, 'a> Deserialize<'de> for Reason<'a> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
type Container<'a> = Empty<ImportedReason<'a>>;
let value = <Container<'a> as Deserialize>::deserialize(deserializer)?;
if value.module_id.is_none() {
Ok(Self::Entry)
} else {
Ok(Self::Imported(value.resolve()))
}
}
}
#[derive(Deserialize, Debug, Default, EmptyType)]
#[serde(rename_all = "camelCase", default)]
#[empty(bounds = "'a", deserialize, default)]
pub struct ImportedReason<'a> {
#[serde(borrow)]
pub loc: Cow<'a, str>,
pub module: RelativeModulePath<'a>,
pub module_id: ModuleId,
pub module_name: ModuleName<'a>,
pub r#type: ImportType,
pub user_request: ImportString<'a>,
}