Skip to main content

icydb_core/
lib.rs

1//! Module: lib
2//! Responsibility: crate root for the IcyDB core runtime surface.
3//! Does not own: canister-facing facade APIs from the public `icydb` crate.
4//! Boundary: exposes the engine subsystems used by schema, query, executor, and storage layers.
5
6//! Core runtime for IcyDB: entity traits, values, executors, visitors, and
7//! the ergonomics exported via the `prelude`.
8#![warn(unreachable_pub)] // too complex to adhere to right now
9
10extern crate self as icydb;
11
12#[macro_use]
13pub(crate) mod scalar_registry;
14
15// public exports are one module level down
16pub mod db;
17pub mod error;
18pub mod metrics;
19pub mod model;
20pub mod sanitize;
21pub mod traits;
22pub mod types;
23pub mod validate;
24pub mod value;
25pub mod visitor;
26
27// testing
28#[cfg(test)]
29pub(crate) mod testing;
30
31///
32/// CONSTANTS
33///
34
35/// Maximum number of indexed fields allowed on an entity.
36///
37/// This limit keeps hashed index keys within bounded, storable sizes and
38/// simplifies sizing tests in the stores.
39pub const MAX_INDEX_FIELDS: usize = 4;
40
41///
42/// Prelude
43///
44/// Prelude contains only domain vocabulary.
45/// No errors, executors, stores, serializers, or helpers are re-exported here.
46///
47
48pub mod prelude {
49    pub use crate::{
50        model::{entity::EntityModel, index::IndexModel},
51        traits::{EntityKind, Path},
52        value::{InputValue, OutputValue},
53    };
54}
55
56// Macro/runtime wiring surface used by generated code in local core tests.
57// This mirrors the facade crate's hidden generated-code boundary so derive
58// output can target one stable path regardless of which workspace crate owns
59// the test harness.
60#[doc(hidden)]
61pub mod __macro {
62    pub use crate::db::{
63        GeneratedStructuralEnumPayload, GeneratedStructuralMapPayloadSlices, PersistedScalar,
64        ScalarSlotValueRef, ScalarValueRef,
65    };
66    pub use crate::error::InternalError;
67    pub use crate::traits::{
68        EnumValue, FieldProjection, PersistedByKindCodec, PersistedFieldMetaCodec,
69        PersistedStructuredFieldCodec, RuntimeValueDecode, RuntimeValueEncode, RuntimeValueKind,
70        RuntimeValueMeta, runtime_value_btree_map_from_value, runtime_value_btree_set_from_value,
71        runtime_value_collection_to_value, runtime_value_from_value, runtime_value_from_vec_into,
72        runtime_value_from_vec_into_btree_map, runtime_value_from_vec_into_btree_set,
73        runtime_value_into, runtime_value_map_collection_to_value, runtime_value_to_value,
74        runtime_value_vec_from_value,
75    };
76    pub use crate::value::{InputValue, Value, ValueEnum};
77
78    #[doc(hidden)]
79    #[must_use]
80    pub fn encode_generated_structural_text_payload_bytes(value: &str) -> Vec<u8> {
81        crate::db::encode_generated_structural_text_payload_bytes(value)
82    }
83
84    #[doc(hidden)]
85    #[must_use]
86    pub fn encode_generated_structural_list_payload_bytes(items: &[&[u8]]) -> Vec<u8> {
87        crate::db::encode_generated_structural_list_payload_bytes(items)
88    }
89
90    #[doc(hidden)]
91    #[must_use]
92    pub fn encode_generated_structural_map_payload_bytes(entries: &[(&[u8], &[u8])]) -> Vec<u8> {
93        crate::db::encode_generated_structural_map_payload_bytes(entries)
94    }
95
96    #[doc(hidden)]
97    #[must_use]
98    pub fn encode_generated_structural_enum_payload_bytes(
99        variant: &str,
100        path: Option<&str>,
101        payload: Option<&[u8]>,
102    ) -> Vec<u8> {
103        crate::db::encode_generated_structural_enum_payload_bytes(variant, path, payload)
104    }
105
106    #[doc(hidden)]
107    pub fn decode_generated_structural_text_payload_bytes(
108        raw_bytes: &[u8],
109    ) -> Result<String, crate::error::InternalError> {
110        crate::db::decode_generated_structural_text_payload_bytes(raw_bytes)
111    }
112
113    #[doc(hidden)]
114    pub fn decode_generated_structural_list_payload_bytes(
115        raw_bytes: &[u8],
116    ) -> Result<Vec<&[u8]>, crate::error::InternalError> {
117        crate::db::decode_generated_structural_list_payload_bytes(raw_bytes)
118    }
119
120    #[doc(hidden)]
121    pub fn decode_generated_structural_map_payload_bytes(
122        raw_bytes: &[u8],
123    ) -> Result<crate::db::GeneratedStructuralMapPayloadSlices<'_>, crate::error::InternalError>
124    {
125        crate::db::decode_generated_structural_map_payload_bytes(raw_bytes)
126    }
127
128    #[doc(hidden)]
129    pub fn decode_generated_structural_enum_payload_bytes(
130        raw_bytes: &[u8],
131    ) -> Result<crate::db::GeneratedStructuralEnumPayload<'_>, crate::error::InternalError> {
132        crate::db::decode_generated_structural_enum_payload_bytes(raw_bytes)
133    }
134
135    #[doc(hidden)]
136    pub fn generated_persisted_structured_payload_decode_failed(
137        detail: impl std::fmt::Display,
138    ) -> crate::error::InternalError {
139        crate::db::generated_persisted_structured_payload_decode_failed(detail)
140    }
141
142    #[doc(hidden)]
143    pub fn encode_persisted_custom_many_slot_payload<T>(
144        value: &[T],
145        field_name: &'static str,
146    ) -> Result<Vec<u8>, crate::error::InternalError>
147    where
148        T: crate::traits::PersistedStructuredFieldCodec + Clone,
149    {
150        crate::db::encode_persisted_custom_many_slot_payload(value, field_name)
151    }
152
153    #[doc(hidden)]
154    pub fn decode_persisted_custom_many_slot_payload<T>(
155        bytes: &[u8],
156        field_name: &'static str,
157    ) -> Result<Vec<T>, crate::error::InternalError>
158    where
159        T: crate::traits::PersistedStructuredFieldCodec,
160    {
161        crate::db::decode_persisted_custom_many_slot_payload(bytes, field_name)
162    }
163
164    #[doc(hidden)]
165    pub fn encode_persisted_custom_slot_payload<T>(
166        value: &T,
167        field_name: &'static str,
168    ) -> Result<Vec<u8>, crate::error::InternalError>
169    where
170        T: crate::traits::PersistedStructuredFieldCodec,
171    {
172        crate::db::encode_persisted_custom_slot_payload(value, field_name)
173    }
174
175    #[doc(hidden)]
176    pub fn decode_persisted_custom_slot_payload<T>(
177        bytes: &[u8],
178        field_name: &'static str,
179    ) -> Result<T, crate::error::InternalError>
180    where
181        T: crate::traits::PersistedStructuredFieldCodec,
182    {
183        crate::db::decode_persisted_custom_slot_payload(bytes, field_name)
184    }
185
186    #[doc(hidden)]
187    pub fn encode_persisted_option_scalar_slot_payload<T>(
188        value: &Option<T>,
189        field_name: &'static str,
190    ) -> Result<Vec<u8>, crate::error::InternalError>
191    where
192        T: PersistedScalar,
193    {
194        crate::db::encode_persisted_option_scalar_slot_payload(value, field_name)
195    }
196
197    #[doc(hidden)]
198    pub fn decode_persisted_option_scalar_slot_payload<T>(
199        bytes: &[u8],
200        field_name: &'static str,
201    ) -> Result<Option<T>, crate::error::InternalError>
202    where
203        T: PersistedScalar,
204    {
205        crate::db::decode_persisted_option_scalar_slot_payload(bytes, field_name)
206    }
207
208    #[doc(hidden)]
209    pub fn encode_persisted_scalar_slot_payload<T>(
210        value: &T,
211        field_name: &'static str,
212    ) -> Result<Vec<u8>, crate::error::InternalError>
213    where
214        T: PersistedScalar,
215    {
216        crate::db::encode_persisted_scalar_slot_payload(value, field_name)
217    }
218
219    #[doc(hidden)]
220    pub fn decode_persisted_scalar_slot_payload<T>(
221        bytes: &[u8],
222        field_name: &'static str,
223    ) -> Result<T, crate::error::InternalError>
224    where
225        T: PersistedScalar,
226    {
227        crate::db::decode_persisted_scalar_slot_payload(bytes, field_name)
228    }
229
230    #[doc(hidden)]
231    pub fn encode_persisted_slot_payload_by_kind<T>(
232        value: &T,
233        kind: crate::model::field::FieldKind,
234        field_name: &'static str,
235    ) -> Result<Vec<u8>, crate::error::InternalError>
236    where
237        T: crate::traits::PersistedByKindCodec,
238    {
239        crate::db::encode_persisted_slot_payload_by_kind(value, kind, field_name)
240    }
241
242    #[doc(hidden)]
243    pub fn decode_persisted_slot_payload_by_kind<T>(
244        bytes: &[u8],
245        kind: crate::model::field::FieldKind,
246        field_name: &'static str,
247    ) -> Result<T, crate::error::InternalError>
248    where
249        T: crate::traits::PersistedByKindCodec,
250    {
251        crate::db::decode_persisted_slot_payload_by_kind(bytes, kind, field_name)
252    }
253
254    #[doc(hidden)]
255    pub fn decode_persisted_option_slot_payload_by_kind<T>(
256        bytes: &[u8],
257        kind: crate::model::field::FieldKind,
258        field_name: &'static str,
259    ) -> Result<Option<T>, crate::error::InternalError>
260    where
261        T: crate::traits::PersistedByKindCodec,
262    {
263        crate::db::decode_persisted_option_slot_payload_by_kind(bytes, kind, field_name)
264    }
265
266    #[doc(hidden)]
267    pub fn encode_persisted_option_slot_payload_by_meta<T>(
268        value: &Option<T>,
269        field_name: &'static str,
270    ) -> Result<Vec<u8>, crate::error::InternalError>
271    where
272        T: crate::traits::PersistedFieldMetaCodec,
273    {
274        crate::db::encode_persisted_option_slot_payload_by_meta(value, field_name)
275    }
276
277    #[doc(hidden)]
278    pub fn decode_persisted_option_slot_payload_by_meta<T>(
279        bytes: &[u8],
280        field_name: &'static str,
281    ) -> Result<Option<T>, crate::error::InternalError>
282    where
283        T: crate::traits::PersistedFieldMetaCodec,
284    {
285        crate::db::decode_persisted_option_slot_payload_by_meta(bytes, field_name)
286    }
287
288    #[doc(hidden)]
289    pub fn encode_persisted_slot_payload_by_meta<T>(
290        value: &T,
291        field_name: &'static str,
292    ) -> Result<Vec<u8>, crate::error::InternalError>
293    where
294        T: crate::traits::PersistedFieldMetaCodec,
295    {
296        crate::db::encode_persisted_slot_payload_by_meta(value, field_name)
297    }
298
299    #[doc(hidden)]
300    pub fn decode_persisted_slot_payload_by_meta<T>(
301        bytes: &[u8],
302        field_name: &'static str,
303    ) -> Result<T, crate::error::InternalError>
304    where
305        T: crate::traits::PersistedFieldMetaCodec,
306    {
307        crate::db::decode_persisted_slot_payload_by_meta(bytes, field_name)
308    }
309}