grafos_store/store.rs
1//! ObjectStore trait definition.
2
3extern crate alloc;
4use alloc::string::String;
5use alloc::vec::Vec;
6
7use grafos_std::error::Result;
8
9#[cfg(feature = "versioning")]
10use crate::meta::VersionInfo;
11use crate::meta::{ObjectInfo, PutOptions};
12use crate::uri::FabricUri;
13
14/// Data returned from a `get()` call.
15#[derive(Clone, Debug, PartialEq)]
16pub struct ObjectData {
17 /// The raw object bytes.
18 pub data: Vec<u8>,
19 /// Object info (size, checksum, content type).
20 pub info: ObjectInfo,
21}
22
23/// Universal object storage trait.
24///
25/// Implementations provide storage backends (memory, block, tiered).
26/// All writes compute and store a CRC32 checksum; all reads verify it.
27pub trait ObjectStore {
28 /// Store an object at the given URI.
29 ///
30 /// If the object already exists, it is overwritten. The CRC32 checksum
31 /// is computed from `data` and stored in the object metadata.
32 fn put(&mut self, uri: &FabricUri, data: &[u8], opts: Option<PutOptions>) -> Result<()>;
33
34 /// Retrieve an object by URI.
35 ///
36 /// Returns `None` if the object does not exist. On a successful read,
37 /// the CRC32 checksum is verified against the stored value.
38 fn get(&self, uri: &FabricUri) -> Result<Option<ObjectData>>;
39
40 /// Retrieve object metadata without reading the data.
41 fn head(&self, uri: &FabricUri) -> Result<Option<ObjectInfo>>;
42
43 /// Delete an object by URI. Returns `true` if the object existed.
44 fn delete(&mut self, uri: &FabricUri) -> Result<bool>;
45
46 /// List object keys matching a prefix within a bucket.
47 ///
48 /// The prefix is matched against the key portion of the URI (not the
49 /// full URI string). An empty prefix lists all keys in the bucket.
50 fn list(&self, pool: &str, bucket: &str, prefix: &str) -> Result<Vec<String>>;
51
52 /// Retrieve a specific version of an object.
53 #[cfg(feature = "versioning")]
54 fn get_version(&self, uri: &FabricUri, version: u64) -> Result<Option<ObjectData>>;
55
56 /// List all versions of an object.
57 #[cfg(feature = "versioning")]
58 fn list_versions(&self, pool: &str, bucket: &str, key: &str) -> Result<Vec<VersionInfo>>;
59
60 /// Delete a specific version of an object. Returns true if the version existed.
61 #[cfg(feature = "versioning")]
62 fn delete_version(&mut self, uri: &FabricUri, version: u64) -> Result<bool>;
63}