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
use serde_reflection::Format;
pub(crate) fn mangle_type(format: &Format) -> String {
use Format::*;
match format {
TypeName(x) => x.to_string(),
Unit => "unit".into(),
Bool => "bool".into(),
I8 => "i8".into(),
I16 => "i16".into(),
I32 => "i32".into(),
I64 => "i64".into(),
I128 => "i128".into(),
U8 => "u8".into(),
U16 => "u16".into(),
U32 => "u32".into(),
U64 => "u64".into(),
U128 => "u128".into(),
F32 => "f32".into(),
F64 => "f64".into(),
Char => "char".into(),
Str => "str".into(),
Bytes => "bytes".into(),
Option(format) => format!("option_{}", mangle_type(format)),
Seq(format) => format!("vector_{}", mangle_type(format)),
Map { key, value } => format!("map_{}_to_{}", mangle_type(key), mangle_type(value)),
Tuple(formats) => format!(
"tuple{}_{}",
formats.len(),
formats
.iter()
.map(mangle_type)
.collect::<Vec<_>>()
.join("_")
),
TupleArray { content, size } => format!("array{}_{}_array", size, mangle_type(content)),
Variable(_) => panic!("unexpected value"),
}
}