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
use PhantomData;
use ;
/// Declares a fixed-length array type for Specta exporters.
///
/// This is primarily useful with `#[specta(type = ...)]` when you want an array
/// field to keep its length information in exported schemas.
///
/// A plain Rust array like `[u8; 2]` may be exported as `number[]` if Specta
/// deems it's unable to safely export it as `[number, number]`. This limitation
/// is due to the fact that Specta can't track the inference of const generics and
/// hence can't fully support them. Using `FixedArray<N, T>` will always encode the
/// length so it can be used to force override Specta's conservative behaviour when you know what your doing.
///
/// ```ignore
/// use specta::Type;
///
/// /// #[derive(Type)]
/// struct DemoA {
/// a: [u8; 2], // becomes `[number, number]`
///
/// #[specta(type = specta_util::FixedArray<2, u8>)]
/// d: [u8; 2], // becomes `[number, number]`
/// }
///
/// #[derive(Type)]
/// struct DemoB<const N: usize = 1> {
/// // These are generalised by Specta as we can't know if a specific type is using `N` or a constant, and we don't know what `N` is.
/// // If you `#[specta(inline)]` or `#[serde(flatten)]` the `[number, number]` will be restored as we are able to track it properly.
/// data: [u32; N], // becomes `number[]`
/// a: [u8; 2], // becomes `number[]`
///
/// #[specta(type = specta_util::FixedArray<2, u8>)]
/// d: [u8; 2], // becomes `[number, number]`
/// }
/// ```
;