use std::{
collections::HashMap,
ops::{Add, AddAssign},
path::PathBuf,
};
use bstr::BString;
use gix_features::threading::OwnShared;
mod mutable;
pub use mutable::{multi_value::MultiValueMut, section::SectionMut, value::ValueMut};
pub mod init;
mod access;
mod impls;
pub mod includes;
mod meta;
mod util;
pub mod section;
pub mod rename_section {
#[derive(Debug, thiserror::Error)]
#[expect(missing_docs)]
pub enum Error {
#[error(transparent)]
Lookup(#[from] crate::lookup::existing::Error),
#[error(transparent)]
Section(#[from] crate::parse::section::header::Error),
}
}
pub mod set_raw_value {
#[derive(Debug, thiserror::Error)]
#[expect(missing_docs)]
pub enum Error {
#[error(transparent)]
Lookup(#[from] crate::lookup::existing::Error),
#[error(transparent)]
Header(#[from] crate::parse::section::header::Error),
#[error(transparent)]
ValueName(#[from] crate::parse::section::value_name::Error),
#[error(transparent)]
Span(#[from] crate::parse::span::Error),
}
}
pub trait IntoBStringOpt {
fn into_bstring_opt(self) -> Option<bstr::BString>;
}
#[derive(Clone, Debug, PartialOrd, PartialEq, Ord, Eq, Hash)]
pub struct Metadata {
pub path: Option<PathBuf>,
pub source: crate::Source,
pub level: u8,
pub trust: gix_sec::Trust,
}
#[derive(Clone, Debug)]
pub(crate) struct SectionData {
pub(crate) header: crate::parse::section::HeaderData,
pub(crate) body: section::BodyData,
pub(crate) meta: OwnShared<Metadata>,
pub(crate) id: SectionId,
}
#[derive(Clone, Debug)]
pub struct Section {
backing: Vec<u8>,
data: SectionData,
}
#[derive(Copy, Clone, Debug)]
pub struct SectionRef<'a> {
data: &'a SectionData,
backing: &'a [u8],
}
#[derive(PartialEq, Eq, Hash, PartialOrd, Ord, Debug, Clone, Copy)]
pub(crate) struct Index(pub(crate) usize);
impl Add<Size> for Index {
type Output = Self;
fn add(self, rhs: Size) -> Self::Output {
Self(self.0 + rhs.0)
}
}
#[derive(PartialEq, Eq, Hash, PartialOrd, Ord, Debug, Clone, Copy)]
pub(crate) struct Size(pub(crate) usize);
impl AddAssign<usize> for Size {
fn add_assign(&mut self, rhs: usize) {
self.0 += rhs;
}
}
#[derive(PartialEq, Eq, Hash, Copy, Clone, PartialOrd, Ord, Debug)]
pub struct SectionId(pub(crate) usize);
impl Default for SectionId {
fn default() -> Self {
SectionId(usize::MAX)
}
}
#[derive(Default, PartialEq, Eq, Clone, Debug)]
pub(crate) struct SectionLookup {
without_subsection: Vec<SectionId>,
by_subsection: HashMap<BString, Vec<SectionId>>,
}
#[cfg(test)]
mod tests;
mod write;