gix_config_value/lib.rs
1//! Parsing for data types used in `git-config` files to allow their use from environment variables and other sources.
2//!
3//! ## Examples
4//!
5//! ```
6//! use bstr::ByteSlice;
7//! use gix_config_value::{Boolean, Integer, Path};
8//!
9//! let auto_crlf: bool = Boolean::try_from("true").unwrap().into();
10//! assert!(auto_crlf);
11//!
12//! let packed_limit = Integer::try_from("10m".as_bytes().as_bstr()).unwrap();
13//! assert_eq!(packed_limit.to_decimal(), Some(10 * 1024 * 1024));
14//!
15//! let ignore_revs = Path::from(":(optional)~/.git-blame-ignore-revs");
16//! assert!(ignore_revs.is_optional);
17//! assert_eq!(ignore_revs.value.as_bstr(), "~/.git-blame-ignore-revs");
18//! ```
19//!
20//! ## Feature Flags
21#![cfg_attr(
22 all(doc, feature = "document-features"),
23 doc = ::document_features::document_features!()
24)]
25#![cfg_attr(all(doc, feature = "document-features"), feature(doc_cfg))]
26#![deny(missing_docs, unsafe_code)]
27
28/// The error returned when any config value couldn't be instantiated due to malformed input.
29#[derive(Debug, thiserror::Error, Eq, PartialEq)]
30#[expect(missing_docs)]
31#[error("Could not decode '{input}': {message}")]
32pub struct Error {
33 pub message: &'static str,
34 pub input: bstr::BString,
35 #[source]
36 pub utf8_err: Option<std::str::Utf8Error>,
37}
38
39impl Error {
40 /// Create a new value error from `message`, with `input` being what's causing the error.
41 pub fn new(message: &'static str, input: impl Into<bstr::BString>) -> Self {
42 Error {
43 message,
44 input: input.into(),
45 utf8_err: None,
46 }
47 }
48
49 pub(crate) fn with_err(mut self, err: std::str::Utf8Error) -> Self {
50 self.utf8_err = Some(err);
51 self
52 }
53}
54
55mod boolean;
56/// Color value parsing and the supported color names and attributes.
57pub mod color;
58/// Integer suffix parsing and conversion support.
59pub mod integer;
60/// Path interpolation support.
61pub mod path;
62
63mod types;
64pub use types::{Boolean, Color, Integer, Path};