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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
use ;
use crate::;
// Global type store for collecting custom types to export.
//
// We intentionally store functions over a `Types` directly to ensure any internal panics aren't done in CTOR.
static TYPES: = new;
/// Get the global type store containing all automatically collected types.
///
/// All types with the [`Type`](macro@crate::Type) macro will automatically be registered here unless they have been explicitly disabled with `#[specta(collect = false)]`.
///
/// Note that when enabling the `export` feature, you will not be able to enable the `unsafe_code` lint as [`small_ctor`] (which is used internally) is marked unsafe.
///
/// # Example
///
/// ```no_run
/// use specta::Type;
/// use specta_typescript::Typescript;
///
/// #[derive(Type)]
/// pub struct User {
/// id: String,
/// name: String,
/// }
///
/// #[derive(Type)]
/// pub struct Post {
/// id: String,
/// author: User,
/// comments: Vec<Comment>,
/// }
///
/// #[derive(Type)]
/// pub struct Comment {
/// body: String,
/// }
///
/// // This type can still derive `Type`, but it is left out of `specta::collect()`.
/// #[derive(Type)]
/// #[specta(collect = false)]
/// pub struct InternalMetrics {
/// latency_ms: u64,
/// }
///
/// fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let output = Typescript::default().export(&specta::collect(), specta_serde::Format)?;
///
/// println!("{output}");
///
/// Ok(())
/// }
/// ```