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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
use crate::*;
use std::collections::{
    BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque,
};
use std::net::IpAddr;
use std::path::{Path, PathBuf};
use std::rc::Rc;
use std::sync::{Arc, Mutex, RwLock};
use std::time::Duration;

document! {
    for String
        => TypeKind::String;

    for IpAddr
        => Type { example: Some(Example::Simple("127.0.0.1")), ..String::ty() };

    /* ----- */

    for Option<T> where (T: Document)
        => TypeKind::Optional {
            ty: Box::new(T::ty()),
        };

    for Box<T> where (T: Document + ?Sized)
        => T::ty();

    for Rc<T> where (T: Document + ?Sized)
        => T::ty();

    for Arc<T> where (T: Document + ?Sized)
        => T::ty();

    for RwLock<T> where (T: Document + ?Sized)
        => T::ty();

    for Mutex<T> where (T: Document + ?Sized)
        => T::ty();

    /* ----- */

    for Vec<T> where (T: Document)
        => <&[T]>::ty();

    for VecDeque<T> where (T: Document)
        => <&[T]>::ty();

    for LinkedList<T> where (T: Document)
        => <&[T]>::ty();

    for HashSet<T> where (T: Document)
        => <&[T]>::ty();

    for BTreeSet<T> where (T: Document)
        => <&[T]>::ty();

    for BinaryHeap<T> where (T: Document)
        => <&[T]>::ty();

    for HashMap<K, V> where (K: Document, V: Document)
        => TypeKind::Map {
            key: Box::new(K::ty()),
            value: Box::new(V::ty()),
        };

    for BTreeMap<K, V> where (K: Document, V: Document)
        => <HashMap<K, V>>::ty();

    for &Path
        => TypeKind::String;

    for PathBuf
        => TypeKind::String;

    /* ----- */

    for Duration
        => duration();
}

fn duration() -> Type {
    Type::from(TypeKind::Struct {
        fields: Fields::Named {
            fields: vec![
                (
                    "secs",
                    Field {
                        ty: Type {
                            example: Some(Example::Simple("123")),
                            ..u64::ty()
                        },
                        flattened: false,
                        aliases: &[],
                    },
                ),
                (
                    "nanos",
                    Field {
                        ty: Type {
                            example: Some(Example::Simple("456000000")),
                            ..u32::ty()
                        },
                        flattened: false,
                        aliases: &[],
                    },
                ),
            ],
        },
        transparent: false,
    })
}