gix_index/file/
mod.rs

1mod impls {
2    use std::ops::{Deref, DerefMut};
3
4    use crate::{File, State};
5
6    impl Deref for File {
7        type Target = State;
8
9        fn deref(&self) -> &Self::Target {
10            &self.state
11        }
12    }
13
14    impl DerefMut for File {
15        fn deref_mut(&mut self) -> &mut Self::Target {
16            &mut self.state
17        }
18    }
19}
20
21mod impl_ {
22    use std::fmt::Formatter;
23
24    use crate::{File, State};
25
26    impl std::fmt::Debug for File {
27        fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
28            f.debug_struct("File")
29                .field("path", &self.path.display())
30                .field("checksum", &self.checksum)
31                .finish_non_exhaustive()
32        }
33    }
34
35    impl From<File> for State {
36        fn from(f: File) -> Self {
37            f.state
38        }
39    }
40}
41
42mod access {
43    use crate::File;
44
45    /// Consumption
46    impl File {
47        /// Take all non-copy parts of the index.
48        pub fn into_parts(self) -> (crate::State, std::path::PathBuf) {
49            (self.state, self.path)
50        }
51    }
52
53    /// Access
54    impl File {
55        /// The path from which the index was read or to which it is supposed to be written when used with [`File::from_state()`].
56        pub fn path(&self) -> &std::path::Path {
57            &self.path
58        }
59
60        /// The checksum over the file that was read or written to disk, or `None` if the state in memory was never serialized.
61        ///
62        /// Note that even if `Some`, it will only represent the state in memory right after reading or [writing][File::write()].
63        pub fn checksum(&self) -> Option<gix_hash::ObjectId> {
64            self.checksum
65        }
66    }
67}
68
69mod mutation {
70    use std::path::PathBuf;
71
72    use crate::File;
73
74    /// Mutating access
75    impl File {
76        /// Set the path at which we think we are located to the given `path`.
77        ///
78        /// This is useful to change the location of the index *once* it is written via [`write()`][File::write()].
79        pub fn set_path(&mut self, path: impl Into<PathBuf>) {
80            self.path = path.into();
81        }
82    }
83}
84
85///
86pub mod init;
87///
88pub mod verify;
89///
90pub mod write;