pub struct SectionMut<'a, 'event> { /* private fields */ }
Expand description
A opaque type that represents a mutable reference to a section.
Implementations§
Source§impl<'event> SectionMut<'_, 'event>
impl<'event> SectionMut<'_, 'event>
Mutating methods.
Sourcepub fn push<'b>(
&mut self,
value_name: ValueName<'event>,
value: Option<&'b BStr>,
) -> &mut Self
pub fn push<'b>( &mut self, value_name: ValueName<'event>, value: Option<&'b BStr>, ) -> &mut Self
Adds an entry to the end of this section name value_name
and value
. If value
is None
, no equal sign will be written leaving
just the key. This is useful for boolean values which are true if merely the key exists.
Sourcepub fn push_with_comment<'b, 'c>(
&mut self,
value_name: ValueName<'event>,
value: Option<&'b BStr>,
comment: impl Into<&'c BStr>,
) -> &mut Self
pub fn push_with_comment<'b, 'c>( &mut self, value_name: ValueName<'event>, value: Option<&'b BStr>, comment: impl Into<&'c BStr>, ) -> &mut Self
Adds an entry to the end of this section name value_name
and value
. If value
is None
, no equal sign will be written leaving
just the key. This is useful for boolean values which are true if merely the key exists.
comment
has to be the text to put right after the value and behind a #
character. Note that newlines are silently transformed
into spaces.
Sourcepub fn pop(&mut self) -> Option<(ValueName<'_>, Cow<'event, BStr>)>
pub fn pop(&mut self) -> Option<(ValueName<'_>, Cow<'event, BStr>)>
Removes all events until a key value pair is removed. This will also remove the whitespace preceding the key value pair, if any is found.
Sourcepub fn set(
&mut self,
value_name: ValueName<'event>,
value: &BStr,
) -> Option<Cow<'event, BStr>>
pub fn set( &mut self, value_name: ValueName<'event>, value: &BStr, ) -> Option<Cow<'event, BStr>>
Sets the last key value pair if it exists, or adds the new value. Returns the previous value if it replaced a value, or None if it adds the value.
Sourcepub fn remove(&mut self, value_name: &str) -> Option<Cow<'event, BStr>>
pub fn remove(&mut self, value_name: &str) -> Option<Cow<'event, BStr>>
Removes the latest value by key and returns it, if it exists.
Sourcepub fn push_newline(&mut self) -> &mut Self
pub fn push_newline(&mut self) -> &mut Self
Adds a new line event. Note that you don’t need to call this unless you’ve disabled implicit newlines.
Sourcepub fn newline(&self) -> &BStr
pub fn newline(&self) -> &BStr
Return the newline used when calling push_newline()
.
Sourcepub fn set_implicit_newline(&mut self, on: bool) -> &mut Self
pub fn set_implicit_newline(&mut self, on: bool) -> &mut Self
Enables or disables automatically adding newline events after adding a value. This is enabled by default.
Sourcepub fn set_leading_whitespace(
&mut self,
whitespace: Option<Cow<'event, BStr>>,
) -> &mut Self
pub fn set_leading_whitespace( &mut self, whitespace: Option<Cow<'event, BStr>>, ) -> &mut Self
Sets the exact whitespace to use before each newly created key-value pair, with only whitespace characters being permissible.
The default is 2 tabs.
Set to None
to disable adding whitespace before a key value.
§Panics
If non-whitespace characters are used. This makes the method only suitable for validated or known input.
Sourcepub fn leading_whitespace(&self) -> Option<&BStr>
pub fn leading_whitespace(&self) -> Option<&BStr>
Returns the whitespace this section will insert before the beginning of a key, if any.
Methods from Deref<Target = Section<'event>>§
Sourcepub fn id(&self) -> SectionId
pub fn id(&self) -> SectionId
Return the unique id
of the section, for use with the *_by_id()
family of methods
in gix_config::File
.
Sourcepub fn to_bstring(&self) -> BString
pub fn to_bstring(&self) -> BString
Serialize this type into a BString
for convenience.
Note that to_string()
can also be used, but might not be lossless.
Methods from Deref<Target = Body<'a>>§
Sourcepub fn value(&self, value_name: impl AsRef<str>) -> Option<Cow<'_, BStr>>
pub fn value(&self, value_name: impl AsRef<str>) -> Option<Cow<'_, BStr>>
Retrieves the last matching value in a section with the given value name, if present.
Note that we consider values without separator =
non-existing, i.e. [core]\na
would not exist.
If that’s expected, Self::value_implicit() must be used instead.
Sourcepub fn value_implicit(&self, value_name: &str) -> Option<Option<Cow<'_, BStr>>>
pub fn value_implicit(&self, value_name: &str) -> Option<Option<Cow<'_, BStr>>>
Retrieves the last matching value in a section with the given value name, if present, and indicates
an implicit value with Some(None)
, and a non-existing one as None
Sourcepub fn values(&self, value_name: &str) -> Vec<Cow<'_, BStr>>
pub fn values(&self, value_name: &str) -> Vec<Cow<'_, BStr>>
Retrieves all values that have the provided value name. This may return an empty vec, which implies there were no values with the provided key.
Sourcepub fn value_names(&self) -> impl Iterator<Item = &ValueName<'event>>
pub fn value_names(&self) -> impl Iterator<Item = &ValueName<'event>>
Returns an iterator visiting all value names in order.
Sourcepub fn contains_value_name(&self, value_name: &str) -> bool
pub fn contains_value_name(&self, value_name: &str) -> bool
Returns true if the section contains the provided value name.
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.