Struct git_config::file::section::Body
source · pub struct Body<'event>(_);
Expand description
A opaque type that represents a section body.
Implementations§
source§impl<'event> Body<'event>
impl<'event> Body<'event>
Access
sourcepub fn value(&self, key: impl AsRef<str>) -> Option<Cow<'_, BStr>>
pub fn value(&self, key: impl AsRef<str>) -> Option<Cow<'_, BStr>>
Retrieves the last matching value in a section with the given key, if present.
Note that we consider values without key separator =
non-existing.
Examples found in repository?
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
pub fn raw_value_filter(
&self,
section_name: impl AsRef<str>,
subsection_name: Option<&BStr>,
key: impl AsRef<str>,
filter: &mut MetadataFilter,
) -> Result<Cow<'_, BStr>, lookup::existing::Error> {
let section_ids = self.section_ids_by_name_and_subname(section_name.as_ref(), subsection_name)?;
let key = key.as_ref();
for section_id in section_ids.rev() {
let section = self.sections.get(§ion_id).expect("known section id");
if !filter(section.meta()) {
continue;
}
if let Some(v) = section.value(key) {
return Ok(v);
}
}
Err(lookup::existing::Error::KeyMissing)
}
sourcepub fn value_implicit(
&self,
key: impl AsRef<str>
) -> Option<Option<Cow<'_, BStr>>>
pub fn value_implicit(
&self,
key: impl AsRef<str>
) -> Option<Option<Cow<'_, BStr>>>
Retrieves the last matching value in a section with the given key, if present, and indicates an implicit value with Some(None)
,
and a non-existing one as None
Examples found in repository?
More examples
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
pub fn boolean_filter(
&self,
section_name: impl AsRef<str>,
subsection_name: Option<&BStr>,
key: impl AsRef<str>,
filter: &mut MetadataFilter,
) -> Option<Result<bool, value::Error>> {
let section_name = section_name.as_ref();
let section_ids = self
.section_ids_by_name_and_subname(section_name, subsection_name)
.ok()?;
let key = key.as_ref();
for section_id in section_ids.rev() {
let section = self.sections.get(§ion_id).expect("known section id");
if !filter(section.meta()) {
continue;
}
match section.value_implicit(key) {
Some(Some(v)) => return Some(crate::Boolean::try_from(v).map(|b| b.into())),
Some(None) => return Some(Ok(true)),
None => continue,
}
}
None
}
sourcepub fn values(&self, key: impl AsRef<str>) -> Vec<Cow<'_, BStr>> ⓘ
pub fn values(&self, key: impl AsRef<str>) -> Vec<Cow<'_, BStr>> ⓘ
Retrieves all values that have the provided key name. This may return an empty vec, which implies there were no values with the provided key.
Examples found in repository?
127 128 129 130 131 132 133 134 135 136 137 138 139
fn detach_include_paths(
include_paths: &mut Vec<(SectionId, crate::Path<'static>)>,
section: &file::Section<'_>,
id: SectionId,
) {
include_paths.extend(
section
.body
.values("path")
.into_iter()
.map(|path| (id, crate::Path::from(Cow::Owned(path.into_owned())))),
)
}
More examples
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
pub fn raw_values_filter(
&self,
section_name: impl AsRef<str>,
subsection_name: Option<&BStr>,
key: impl AsRef<str>,
filter: &mut MetadataFilter,
) -> Result<Vec<Cow<'_, BStr>>, lookup::existing::Error> {
let mut values = Vec::new();
let section_ids = self.section_ids_by_name_and_subname(section_name.as_ref(), subsection_name)?;
let key = key.as_ref();
for section_id in section_ids {
let section = self.sections.get(§ion_id).expect("known section id");
if !filter(section.meta()) {
continue;
}
values.extend(section.values(key));
}
if values.is_empty() {
Err(lookup::existing::Error::KeyMissing)
} else {
Ok(values)
}
}
sourcepub fn keys(&self) -> impl Iterator<Item = &Key<'event>>
pub fn keys(&self) -> impl Iterator<Item = &Key<'event>>
Returns an iterator visiting all keys in order.
sourcepub fn contains_key(&self, key: impl AsRef<str>) -> bool
pub fn contains_key(&self, key: impl AsRef<str>) -> bool
Returns true if the section containss the provided key.
sourcepub fn num_values(&self) -> usize
pub fn num_values(&self) -> usize
Returns the number of values in the section.
sourcepub fn is_void(&self) -> bool
pub fn is_void(&self) -> bool
Returns if the section is empty.
Note that this may count whitespace, see num_values()
for
another way to determine semantic emptiness.
Trait Implementations§
source§impl<'event> IntoIterator for Body<'event>
impl<'event> IntoIterator for Body<'event>
source§impl<'event> Ord for Body<'event>
impl<'event> Ord for Body<'event>
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl<'event> PartialEq<Body<'event>> for Body<'event>
impl<'event> PartialEq<Body<'event>> for Body<'event>
source§impl<'event> PartialOrd<Body<'event>> for Body<'event>
impl<'event> PartialOrd<Body<'event>> for Body<'event>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more