git_internal/internal/metadata/
mod.rs

1//! Lightweight metadata plumbing that allows pack entries to carry auxiliary information (paths,
2//! pack offsets, CRC32, etc.) through encode/decode pipelines without polluting core types.
3
4mod entry_meta;
5use std::fmt;
6
7pub use entry_meta::EntryMeta;
8
9/// Trait for types that can carry metadata.
10pub trait MetadataExt {
11    type Meta: Clone + std::fmt::Debug + Send + Sync + 'static;
12
13    fn metadata(&self) -> Option<&Self::Meta>;
14    fn metadata_mut(&mut self) -> Option<&mut Self::Meta>;
15    fn set_metadata(&mut self, meta: Self::Meta);
16    //fn clear_metadata(&mut self);
17}
18
19/// Wrapper type that attaches metadata to an inner type.
20#[derive(Debug, Clone)]
21pub struct MetaAttached<T, M> {
22    pub inner: T,
23    pub meta: M,
24}
25
26impl<T, M> MetadataExt for MetaAttached<T, M>
27where
28    M: Clone + std::fmt::Debug + Send + Sync + 'static,
29{
30    type Meta = M;
31
32    fn metadata(&self) -> Option<&Self::Meta> {
33        Some(&self.meta)
34    }
35
36    fn metadata_mut(&mut self) -> Option<&mut Self::Meta> {
37        Some(&mut self.meta)
38    }
39
40    fn set_metadata(&mut self, meta: Self::Meta) {
41        self.meta = meta;
42    }
43
44    // fn clear_metadata(&mut self) {
45    //
46    // }
47}
48
49impl<T, M> fmt::Display for MetaAttached<T, M>
50where
51    T: fmt::Display,
52    M: fmt::Debug,
53{
54    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
55        write!(f, "{} | meta: {:?}", self.inner, self.meta)
56    }
57}