1#![warn(unreachable_pub)]
9#![cfg_attr(all(test, not(feature = "sql")), allow(dead_code))]
13
14extern crate self as icydb;
15
16#[macro_use]
17pub(crate) mod scalar_registry;
18
19pub mod db;
21pub mod error;
22pub mod metrics;
23pub mod model;
24pub(crate) mod runtime;
25pub mod sanitize;
26pub mod traits;
27pub mod types;
28pub mod validate;
29pub mod value;
30pub mod visitor;
31
32#[cfg(test)]
34pub(crate) mod testing;
35
36pub const MAX_INDEX_FIELDS: usize = 4;
45
46pub mod prelude {
54 pub use crate::{
55 model::{entity::EntityModel, index::IndexModel},
56 traits::{EntityKind, Path},
57 value::{InputValue, OutputValue},
58 };
59}
60
61#[doc(hidden)]
66pub mod __macro {
67 #[doc(hidden)]
68 pub fn decode_generated_runtime_field_value<T>(
69 value: &crate::value::Value,
70 context: Option<&dyn crate::traits::RuntimeEnumContext>,
71 field_name: &'static str,
72 ) -> Result<T, crate::error::InternalError>
73 where
74 T: crate::traits::RuntimeValueDecode,
75 {
76 crate::traits::runtime_value_from_value_with_optional_enum_context(value, context)
77 .ok_or_else(|| {
78 crate::error::InternalError::persisted_row_field_decode_failed(field_name, ())
79 })
80 }
81
82 pub use crate::db::{
83 CompositePrimaryKeyValue, CompositePrimaryKeyValueError,
84 GeneratedStructuralMapPayloadSlices, JournalTailStore, PersistedRow, PersistedScalar,
85 PrimaryKeyComponent, PrimaryKeyValue, ScalarSlotValueRef, ScalarValueRef, SlotReader,
86 StoreRuntimeStorageCapabilities,
87 };
88 pub use crate::error::{ErrorClass, ErrorOrigin, InternalError};
89 pub use crate::traits::{
90 AuthoredFieldProjection, EntityKeyBytes, FieldProjection, KeyValueCodec,
91 PersistedByKindCodec, PersistedStructuredFieldCodec, PrimaryKeyCodec, PrimaryKeyDecode,
92 PrimaryKeyEncodeError, RuntimeEnumContext, RuntimeEnumSelection, RuntimeValueDecode,
93 RuntimeValueEncode, RuntimeValueKind, RuntimeValueMeta, ScalarRelationTargetKey,
94 ScalarRelationTargetKeyMatchesDeclaredPrimitive, runtime_value_btree_map_from_value,
95 runtime_value_btree_set_from_value, runtime_value_collection_to_value,
96 runtime_value_from_value, runtime_value_from_value_with_enum_context,
97 runtime_value_from_value_with_optional_enum_context, runtime_value_from_vec_into,
98 runtime_value_from_vec_into_btree_map, runtime_value_from_vec_into_btree_set,
99 runtime_value_into, runtime_value_map_collection_to_value, runtime_value_to_value,
100 runtime_value_vec_from_value,
101 };
102 pub use crate::value::{InputValue, InputValueEnum, Value, ValueEnum};
103 pub use ic_memory::{
104 bootstrap_default_memory_manager, ic_memory_declaration, ic_memory_key, ic_memory_range,
105 };
106
107 #[doc(hidden)]
108 #[must_use]
109 pub fn encode_generated_structural_text_payload_bytes(value: &str) -> Vec<u8> {
110 crate::db::encode_generated_structural_text_payload_bytes(value)
111 }
112
113 #[doc(hidden)]
114 #[must_use]
115 pub fn encode_generated_structural_list_payload_bytes(items: &[&[u8]]) -> Vec<u8> {
116 crate::db::encode_generated_structural_list_payload_bytes(items)
117 }
118
119 #[doc(hidden)]
120 #[must_use]
121 pub fn encode_generated_structural_map_payload_bytes(entries: &[(&[u8], &[u8])]) -> Vec<u8> {
122 crate::db::encode_generated_structural_map_payload_bytes(entries)
123 }
124
125 #[doc(hidden)]
126 pub fn decode_generated_structural_text_payload_bytes(
127 raw_bytes: &[u8],
128 ) -> Result<String, crate::error::InternalError> {
129 crate::db::decode_generated_structural_text_payload_bytes(raw_bytes)
130 }
131
132 #[doc(hidden)]
133 pub fn decode_generated_structural_list_payload_bytes(
134 raw_bytes: &[u8],
135 ) -> Result<Vec<&[u8]>, crate::error::InternalError> {
136 crate::db::decode_generated_structural_list_payload_bytes(raw_bytes)
137 }
138
139 #[doc(hidden)]
140 pub fn decode_generated_structural_map_payload_bytes(
141 raw_bytes: &[u8],
142 ) -> Result<crate::db::GeneratedStructuralMapPayloadSlices<'_>, crate::error::InternalError>
143 {
144 crate::db::decode_generated_structural_map_payload_bytes(raw_bytes)
145 }
146
147 #[doc(hidden)]
148 pub fn generated_persisted_structured_payload_decode_failed(
149 detail: impl std::fmt::Display,
150 ) -> crate::error::InternalError {
151 crate::db::generated_persisted_structured_payload_decode_failed(detail)
152 }
153
154 #[doc(hidden)]
155 pub fn encode_non_enum_protocol_value_bytes(
156 value: &crate::value::Value,
157 ) -> Result<Vec<u8>, crate::error::InternalError> {
158 crate::db::encode_non_enum_protocol_value_bytes(value)
159 }
160
161 #[doc(hidden)]
162 pub fn decode_non_enum_protocol_value_bytes(
163 raw_bytes: &[u8],
164 ) -> Result<crate::value::Value, crate::error::InternalError> {
165 crate::db::decode_non_enum_protocol_value_bytes(raw_bytes)
166 }
167
168 #[doc(hidden)]
169 pub fn encode_persisted_structured_many_slot_payload<T>(
170 value: &[T],
171 field_name: &'static str,
172 ) -> Result<Vec<u8>, crate::error::InternalError>
173 where
174 T: crate::traits::PersistedStructuredFieldCodec,
175 {
176 crate::db::encode_persisted_structured_many_slot_payload(value, field_name)
177 }
178
179 #[doc(hidden)]
180 pub fn decode_persisted_structured_many_slot_payload<T>(
181 bytes: &[u8],
182 field_name: &'static str,
183 ) -> Result<Vec<T>, crate::error::InternalError>
184 where
185 T: crate::traits::PersistedStructuredFieldCodec,
186 {
187 crate::db::decode_persisted_structured_many_slot_payload(bytes, field_name)
188 }
189
190 #[doc(hidden)]
191 pub fn encode_persisted_structured_slot_payload<T>(
192 value: &T,
193 field_name: &'static str,
194 ) -> Result<Vec<u8>, crate::error::InternalError>
195 where
196 T: crate::traits::PersistedStructuredFieldCodec,
197 {
198 crate::db::encode_persisted_structured_slot_payload(value, field_name)
199 }
200
201 #[doc(hidden)]
202 pub fn decode_persisted_structured_slot_payload<T>(
203 bytes: &[u8],
204 field_name: &'static str,
205 ) -> Result<T, crate::error::InternalError>
206 where
207 T: crate::traits::PersistedStructuredFieldCodec,
208 {
209 crate::db::decode_persisted_structured_slot_payload(bytes, field_name)
210 }
211
212 #[doc(hidden)]
213 pub fn encode_persisted_option_scalar_slot_payload<T>(
214 value: &Option<T>,
215 field_name: &'static str,
216 ) -> Result<Vec<u8>, crate::error::InternalError>
217 where
218 T: PersistedScalar,
219 {
220 crate::db::encode_persisted_option_scalar_slot_payload(value, field_name)
221 }
222
223 #[doc(hidden)]
224 pub fn decode_persisted_option_scalar_slot_payload<T>(
225 bytes: &[u8],
226 field_name: &'static str,
227 ) -> Result<Option<T>, crate::error::InternalError>
228 where
229 T: PersistedScalar,
230 {
231 crate::db::decode_persisted_option_scalar_slot_payload(bytes, field_name)
232 }
233
234 #[doc(hidden)]
235 pub fn encode_persisted_scalar_slot_payload<T>(
236 value: &T,
237 field_name: &'static str,
238 ) -> Result<Vec<u8>, crate::error::InternalError>
239 where
240 T: PersistedScalar,
241 {
242 crate::db::encode_persisted_scalar_slot_payload(value, field_name)
243 }
244
245 #[doc(hidden)]
246 pub fn decode_persisted_scalar_slot_payload<T>(
247 bytes: &[u8],
248 field_name: &'static str,
249 ) -> Result<T, crate::error::InternalError>
250 where
251 T: PersistedScalar,
252 {
253 crate::db::decode_persisted_scalar_slot_payload(bytes, field_name)
254 }
255
256 #[doc(hidden)]
257 pub fn encode_persisted_slot_payload_by_kind<T>(
258 value: &T,
259 kind: crate::model::field::FieldKind,
260 field_name: &'static str,
261 ) -> Result<Vec<u8>, crate::error::InternalError>
262 where
263 T: crate::traits::PersistedByKindCodec,
264 {
265 crate::db::encode_persisted_slot_payload_by_kind(value, kind, field_name)
266 }
267
268 #[doc(hidden)]
269 pub fn decode_persisted_slot_payload_by_kind<T>(
270 bytes: &[u8],
271 kind: crate::model::field::FieldKind,
272 field_name: &'static str,
273 ) -> Result<T, crate::error::InternalError>
274 where
275 T: crate::traits::PersistedByKindCodec,
276 {
277 crate::db::decode_persisted_slot_payload_by_kind(bytes, kind, field_name)
278 }
279
280 #[doc(hidden)]
281 pub fn decode_persisted_option_slot_payload_by_kind<T>(
282 bytes: &[u8],
283 kind: crate::model::field::FieldKind,
284 field_name: &'static str,
285 ) -> Result<Option<T>, crate::error::InternalError>
286 where
287 T: crate::traits::PersistedByKindCodec,
288 {
289 crate::db::decode_persisted_option_slot_payload_by_kind(bytes, kind, field_name)
290 }
291}