35 35 | self.shape_type
|
36 36 | }
|
37 37 |
|
38 38 | fn traits(&self) -> &TraitMap {
|
39 39 | static MAP: LazyLock<TraitMap> = LazyLock::new(TraitMap::empty);
|
40 40 |
|
41 41 | &MAP
|
42 42 | }
|
43 43 | }
|
44 44 |
|
45 - | // TODO(schema): We should probably test with these as `pub static` too since that could
|
46 - | // theoretically cut down on binary size (at the expense of some runtime performance)
|
45 + | // Static schemas for prelude types to allow static lifetime references
|
47 46 |
|
48 47 | /// Schema for `smithy.api#String`
|
49 - | pub const STRING: PreludeSchema = PreludeSchema::new(
|
48 + | pub static STRING: PreludeSchema = PreludeSchema::new(
|
50 49 | ShapeId::from_static("smithy.api#String", "smithy.api", "String"),
|
51 50 | ShapeType::String,
|
52 51 | );
|
53 52 |
|
54 53 | /// Schema for `smithy.api#Boolean`
|
55 - | pub const BOOLEAN: PreludeSchema = PreludeSchema::new(
|
54 + | pub static BOOLEAN: PreludeSchema = PreludeSchema::new(
|
56 55 | ShapeId::from_static("smithy.api#Boolean", "smithy.api", "Boolean"),
|
57 56 | ShapeType::Boolean,
|
58 57 | );
|
59 58 |
|
60 59 | /// Schema for `smithy.api#Byte`
|
61 - | pub const BYTE: PreludeSchema = PreludeSchema::new(
|
60 + | pub static BYTE: PreludeSchema = PreludeSchema::new(
|
62 61 | ShapeId::from_static("smithy.api#Byte", "smithy.api", "Byte"),
|
63 62 | ShapeType::Byte,
|
64 63 | );
|
65 64 |
|
66 65 | /// Schema for `smithy.api#Short`
|
67 - | pub const SHORT: PreludeSchema = PreludeSchema::new(
|
66 + | pub static SHORT: PreludeSchema = PreludeSchema::new(
|
68 67 | ShapeId::from_static("smithy.api#Short", "smithy.api", "Short"),
|
69 68 | ShapeType::Short,
|
70 69 | );
|
71 70 |
|
72 71 | /// Schema for `smithy.api#Integer`
|
73 - | pub const INTEGER: PreludeSchema = PreludeSchema::new(
|
72 + | pub static INTEGER: PreludeSchema = PreludeSchema::new(
|
74 73 | ShapeId::from_static("smithy.api#Integer", "smithy.api", "Integer"),
|
75 74 | ShapeType::Integer,
|
76 75 | );
|
77 76 |
|
78 77 | /// Schema for `smithy.api#Long`
|
79 - | pub const LONG: PreludeSchema = PreludeSchema::new(
|
78 + | pub static LONG: PreludeSchema = PreludeSchema::new(
|
80 79 | ShapeId::from_static("smithy.api#Long", "smithy.api", "Long"),
|
81 80 | ShapeType::Long,
|
82 81 | );
|
83 82 |
|
84 83 | /// Schema for `smithy.api#Float`
|
85 - | pub const FLOAT: PreludeSchema = PreludeSchema::new(
|
84 + | pub static FLOAT: PreludeSchema = PreludeSchema::new(
|
86 85 | ShapeId::from_static("smithy.api#Float", "smithy.api", "Float"),
|
87 86 | ShapeType::Float,
|
88 87 | );
|
89 88 |
|
90 89 | /// Schema for `smithy.api#Double`
|
91 - | pub const DOUBLE: PreludeSchema = PreludeSchema::new(
|
90 + | pub static DOUBLE: PreludeSchema = PreludeSchema::new(
|
92 91 | ShapeId::from_static("smithy.api#Double", "smithy.api", "Double"),
|
93 92 | ShapeType::Double,
|
94 93 | );
|
95 94 |
|
96 95 | /// Schema for `smithy.api#BigInteger`
|
97 - | pub const BIG_INTEGER: PreludeSchema = PreludeSchema::new(
|
96 + | pub static BIG_INTEGER: PreludeSchema = PreludeSchema::new(
|
98 97 | ShapeId::from_static("smithy.api#BigInteger", "smithy.api", "BigInteger"),
|
99 98 | ShapeType::BigInteger,
|
100 99 | );
|
101 100 |
|
102 101 | /// Schema for `smithy.api#BigDecimal`
|
103 - | pub const BIG_DECIMAL: PreludeSchema = PreludeSchema::new(
|
102 + | pub static BIG_DECIMAL: PreludeSchema = PreludeSchema::new(
|
104 103 | ShapeId::from_static("smithy.api#BigDecimal", "smithy.api", "BigDecimal"),
|
105 104 | ShapeType::BigDecimal,
|
106 105 | );
|
107 106 |
|
108 107 | /// Schema for `smithy.api#Blob`
|
109 - | pub const BLOB: PreludeSchema = PreludeSchema::new(
|
108 + | pub static BLOB: PreludeSchema = PreludeSchema::new(
|
110 109 | ShapeId::from_static("smithy.api#Blob", "smithy.api", "Blob"),
|
111 110 | ShapeType::Blob,
|
112 111 | );
|
113 112 |
|
114 113 | /// Schema for `smithy.api#Timestamp`
|
115 - | pub const TIMESTAMP: PreludeSchema = PreludeSchema::new(
|
114 + | pub static TIMESTAMP: PreludeSchema = PreludeSchema::new(
|
116 115 | ShapeId::from_static("smithy.api#Timestamp", "smithy.api", "Timestamp"),
|
117 116 | ShapeType::Timestamp,
|
118 117 | );
|
119 118 |
|
120 119 | /// Schema for `smithy.api#Document`
|
121 - | pub const DOCUMENT: PreludeSchema = PreludeSchema::new(
|
120 + | pub static DOCUMENT: PreludeSchema = PreludeSchema::new(
|
122 121 | ShapeId::from_static("smithy.api#Document", "smithy.api", "Document"),
|
123 122 | ShapeType::Document,
|
124 123 | );
|
125 124 |
|
126 125 | #[cfg(test)]
|
127 126 | mod tests {
|
128 127 | use super::*;
|
129 128 | use crate::SchemaExt;
|
130 129 |
|
131 130 | #[test]
|
132 131 | fn test_string_schema() {
|
133 132 | assert_eq!(STRING.shape_id().as_str(), "smithy.api#String");
|
134 133 | assert_eq!(STRING.shape_type(), ShapeType::String);
|
135 134 | assert!(STRING.is_string());
|
136 135 | assert!(STRING.traits().is_empty());
|
137 136 | }
|
138 137 |
|
139 138 | #[test]
|
140 139 | fn test_boolean_schema() {
|
141 140 | assert_eq!(BOOLEAN.shape_id().as_str(), "smithy.api#Boolean");
|
142 141 | assert_eq!(BOOLEAN.shape_type(), ShapeType::Boolean);
|
143 142 | assert!(BOOLEAN.traits().is_empty());
|
144 143 | }
|
145 144 |
|
146 145 | #[test]
|
147 146 | fn test_numeric_schemas() {
|
148 147 | assert_eq!(BYTE.shape_type(), ShapeType::Byte);
|
149 148 | assert_eq!(SHORT.shape_type(), ShapeType::Short);
|
150 149 | assert_eq!(INTEGER.shape_type(), ShapeType::Integer);
|
151 150 | assert_eq!(LONG.shape_type(), ShapeType::Long);
|