1use std::{
3 collections::HashMap,
4 ops::{Add, AddAssign},
5 path::PathBuf,
6};
7
8use bstr::BString;
9use gix_features::threading::OwnShared;
10
11mod mutable;
12pub use mutable::{multi_value::MultiValueMut, section::SectionMut, value::ValueMut};
13
14pub mod init;
16
17mod access;
18mod impls;
19pub mod includes;
21mod meta;
22mod util;
23
24pub mod section;
26
27pub mod rename_section {
29 #[derive(Debug, thiserror::Error)]
31 #[expect(missing_docs)]
32 pub enum Error {
33 #[error(transparent)]
34 Lookup(#[from] crate::lookup::existing::Error),
35 #[error(transparent)]
36 Section(#[from] crate::parse::section::header::Error),
37 }
38}
39
40pub mod set_raw_value {
42 #[derive(Debug, thiserror::Error)]
44 #[expect(missing_docs)]
45 pub enum Error {
46 #[error(transparent)]
47 Lookup(#[from] crate::lookup::existing::Error),
48 #[error(transparent)]
49 Header(#[from] crate::parse::section::header::Error),
50 #[error(transparent)]
51 ValueName(#[from] crate::parse::section::value_name::Error),
52 #[error(transparent)]
53 Span(#[from] crate::parse::span::Error),
54 }
55}
56
57pub trait IntoBStringOpt {
59 fn into_bstring_opt(self) -> Option<bstr::BString>;
61}
62
63#[derive(Clone, Debug, PartialOrd, PartialEq, Ord, Eq, Hash)]
65pub struct Metadata {
66 pub path: Option<PathBuf>,
68 pub source: crate::Source,
70 pub level: u8,
74 pub trust: gix_sec::Trust,
76}
77
78#[derive(Clone, Debug)]
79pub(crate) struct SectionData {
80 pub(crate) header: crate::parse::section::HeaderData,
81 pub(crate) body: section::BodyData,
82 pub(crate) meta: OwnShared<Metadata>,
83 pub(crate) id: SectionId,
84}
85
86#[derive(Clone, Debug)]
91pub struct Section {
92 backing: Vec<u8>,
93 data: SectionData,
94}
95
96#[derive(Copy, Clone, Debug)]
100pub struct SectionRef<'a> {
101 data: &'a SectionData,
102 backing: &'a [u8],
103}
104
105#[derive(PartialEq, Eq, Hash, PartialOrd, Ord, Debug, Clone, Copy)]
107pub(crate) struct Index(pub(crate) usize);
108
109impl Add<Size> for Index {
110 type Output = Self;
111
112 fn add(self, rhs: Size) -> Self::Output {
113 Self(self.0 + rhs.0)
114 }
115}
116
117#[derive(PartialEq, Eq, Hash, PartialOrd, Ord, Debug, Clone, Copy)]
119pub(crate) struct Size(pub(crate) usize);
120
121impl AddAssign<usize> for Size {
122 fn add_assign(&mut self, rhs: usize) {
123 self.0 += rhs;
124 }
125}
126
127#[derive(PartialEq, Eq, Hash, Copy, Clone, PartialOrd, Ord, Debug)]
138pub struct SectionId(pub(crate) usize);
139
140impl Default for SectionId {
141 fn default() -> Self {
142 SectionId(usize::MAX)
143 }
144}
145
146#[derive(Default, PartialEq, Eq, Clone, Debug)]
148pub(crate) struct SectionLookup {
149 without_subsection: Vec<SectionId>,
150 by_subsection: HashMap<BString, Vec<SectionId>>,
151}
152#[cfg(test)]
153mod tests;
154mod write;