Skip to main content

harmos_storage/
writes.rs

1/* ***
2 *
3 * Harmos
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * ***
8 */
9
10/* === Modules === */
11
12pub mod convert;
13mod decoded;
14
15/* === Re-Exports === */
16
17pub use decoded::DecodedBatch;
18pub use harmos_domain::model::storage::{BatchReceipt, DataBatch, WriteCompletion, WriteReceipt};
19
20/* === Imports === */
21
22// Standard Library Imports
23use std::sync::Arc;
24// Third Party Imports
25// Local Imports
26use super::{SchemaKey, StorageCursor};
27use crate::MemorySize;
28use crate::schema::graph::Schema;
29
30/* === Constants === */
31
32/* === Macros === */
33
34/* === Type Aliases === */
35
36/* === Structs === */
37
38#[derive(Clone, Debug, PartialEq, Eq)]
39pub struct StorageSchema {
40    pub position: StorageCursor,
41    pub key: SchemaKey,
42    pub schema: Arc<Schema>,
43}
44
45/* === Enums === */
46
47/* === Traits === */
48
49/* === Implementations === */
50
51impl MemorySize for StorageSchema {
52    fn memory_size(&self) -> usize {
53        std::mem::size_of::<Self>()
54            .saturating_add(self.position.memory_size().saturating_sub(std::mem::size_of::<StorageCursor>()))
55            .saturating_add(self.key.memory_size().saturating_sub(std::mem::size_of::<SchemaKey>()))
56            .saturating_add(self.schema.memory_size().saturating_add(2 * std::mem::size_of::<usize>()))
57    }
58}
59
60impl StorageSchema {
61    pub fn new(position: StorageCursor, key: SchemaKey, schema: impl Into<Arc<Schema>>) -> Self {
62        Self { position, key, schema: schema.into() }
63    }
64}
65
66/* === Public Functions === */
67
68/* === Private Functions === */
69
70/* === Tests === */