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