Struct git_repository::config::file::SectionMut
source · [−]pub struct SectionMut<'a, 'event> { /* private fields */ }
Expand description
A opaque type that represents a mutable reference to a section.
Implementations
sourceimpl<'a, 'event> SectionMut<'a, 'event>
impl<'a, 'event> SectionMut<'a, 'event>
Mutating methods.
sourcepub fn push<'b>(&mut self, key: Key<'event>, value: impl Into<&'b BStr>)
pub fn push<'b>(&mut self, key: Key<'event>, value: impl Into<&'b BStr>)
Adds an entry to the end of this section name key
and value
.
sourcepub fn pop(&mut self) -> Option<(Key<'_>, Cow<'event, BStr>)>
pub fn pop(&mut self) -> Option<(Key<'_>, 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<'b>(
&mut self,
key: Key<'event>,
value: impl Into<&'b BStr>
) -> Option<Cow<'event, BStr>>
pub fn set<'b>(
&mut self,
key: Key<'event>,
value: impl Into<&'b 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, key: impl AsRef<str>) -> Option<Cow<'event, BStr>>
pub fn remove(&mut self, key: impl AsRef<str>) -> Option<Cow<'event, BStr>>
Removes the latest value by key and returns it, if it exists.
sourcepub fn push_newline(&mut self)
pub fn push_newline(&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)
pub fn set_implicit_newline(&mut self, on: bool)
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>>)
pub fn set_leading_whitespace(&mut self, whitespace: Option<Cow<'event, BStr>>)
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.
sourcepub fn separator_whitespace(&self) -> (Option<&BStr>, Option<&BStr>)
pub fn separator_whitespace(&self) -> (Option<&BStr>, Option<&BStr>)
Returns the whitespace to be used before and after the =
between the key
and the value.
For example, k = v
will have (Some(" "), Some(" "))
, whereas k=\tv
will
have (None, Some("\t"))
.
Methods from Deref<Target = Section<'event>>
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, 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.
sourcepub fn values(&self, key: impl AsRef<str>) -> Vec<Cow<'_, BStr>, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn values(&self, key: impl AsRef<str>) -> Vec<Cow<'_, BStr>, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
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.
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
sourceimpl<'a, 'event> Debug for SectionMut<'a, 'event>
impl<'a, 'event> Debug for SectionMut<'a, 'event>
sourceimpl<'event> Deref for SectionMut<'_, 'event>
impl<'event> Deref for SectionMut<'_, 'event>
sourceimpl<'a, 'event> Hash for SectionMut<'a, 'event>
impl<'a, 'event> Hash for SectionMut<'a, 'event>
sourceimpl<'a, 'event> Ord for SectionMut<'a, 'event>
impl<'a, 'event> Ord for SectionMut<'a, 'event>
sourceimpl<'a, 'event> PartialEq<SectionMut<'a, 'event>> for SectionMut<'a, 'event>
impl<'a, 'event> PartialEq<SectionMut<'a, 'event>> for SectionMut<'a, 'event>
sourcefn eq(&self, other: &SectionMut<'a, 'event>) -> bool
fn eq(&self, other: &SectionMut<'a, 'event>) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &SectionMut<'a, 'event>) -> bool
fn ne(&self, other: &SectionMut<'a, 'event>) -> bool
This method tests for !=
.
sourceimpl<'a, 'event> PartialOrd<SectionMut<'a, 'event>> for SectionMut<'a, 'event>
impl<'a, 'event> PartialOrd<SectionMut<'a, 'event>> for SectionMut<'a, 'event>
sourcefn partial_cmp(&self, other: &SectionMut<'a, 'event>) -> Option<Ordering>
fn partial_cmp(&self, other: &SectionMut<'a, 'event>) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl<'a, 'event> Eq for SectionMut<'a, 'event>
impl<'a, 'event> StructuralEq for SectionMut<'a, 'event>
impl<'a, 'event> StructuralPartialEq for SectionMut<'a, 'event>
Auto Trait Implementations
impl<'a, 'event> RefUnwindSafe for SectionMut<'a, 'event>
impl<'a, 'event> Send for SectionMut<'a, 'event>
impl<'a, 'event> Sync for SectionMut<'a, 'event>
impl<'a, 'event> Unpin for SectionMut<'a, 'event> where
'event: 'a,
impl<'a, 'event> !UnwindSafe for SectionMut<'a, 'event>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more