grafos_store/
meta.rs

1//! Object metadata types.
2
3extern crate alloc;
4use alloc::string::String;
5use alloc::vec::Vec;
6
7use serde::{Deserialize, Serialize};
8
9/// Metadata stored alongside an object.
10#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
11pub struct ObjectMeta {
12    /// MIME content type (e.g. `"application/octet-stream"`).
13    pub content_type: String,
14    /// CRC32 checksum of the object data.
15    pub crc32: u32,
16    /// Object size in bytes.
17    pub size: u64,
18    /// Creation timestamp (unix seconds).
19    pub created_at: u64,
20    /// Optional user-defined tags (key-value pairs).
21    pub tags: Vec<(String, String)>,
22    /// Version number (incremented on each put when versioning is enabled).
23    #[cfg(feature = "versioning")]
24    pub version: u64,
25}
26
27/// Lightweight object info returned by `head()`.
28#[derive(Clone, Debug, PartialEq)]
29pub struct ObjectInfo {
30    /// Object size in bytes.
31    pub size: u64,
32    /// CRC32 checksum.
33    pub crc32: u32,
34    /// MIME content type.
35    pub content_type: String,
36    /// Creation timestamp (unix seconds).
37    pub created_at: u64,
38    /// Version number (when versioning is enabled).
39    #[cfg(feature = "versioning")]
40    pub version: u64,
41}
42
43impl ObjectInfo {
44    /// Build ObjectInfo from ObjectMeta.
45    pub fn from_meta(meta: &ObjectMeta) -> Self {
46        ObjectInfo {
47            size: meta.size,
48            crc32: meta.crc32,
49            content_type: meta.content_type.clone(),
50            created_at: meta.created_at,
51            #[cfg(feature = "versioning")]
52            version: meta.version,
53        }
54    }
55}
56
57/// Information about a specific object version.
58#[cfg(feature = "versioning")]
59#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
60pub struct VersionInfo {
61    /// Version number.
62    pub version: u64,
63    /// Object size in bytes.
64    pub size: u64,
65    /// Creation timestamp (unix seconds).
66    pub created_at: u64,
67}
68
69/// Options for a put operation.
70#[derive(Clone, Debug, Default)]
71pub struct PutOptions {
72    /// Content type override. Defaults to `"application/octet-stream"`.
73    pub content_type: Option<String>,
74    /// User-defined tags.
75    pub tags: Vec<(String, String)>,
76}