Struct git_config::file::MutableSection
source · [−]pub struct MutableSection<'borrow, 'event> { /* private fields */ }
Expand description
A opaque type that represents a mutable reference to a section.
Implementations
sourceimpl<'borrow, 'event> MutableSection<'borrow, 'event>
impl<'borrow, 'event> MutableSection<'borrow, 'event>
sourcepub fn push(&mut self, key: Key<'event>, value: Cow<'event, [u8]>)
pub fn push(&mut self, key: Key<'event>, value: Cow<'event, [u8]>)
Adds an entry to the end of this section.
sourcepub fn pop(&mut self) -> Option<(Key<'_>, Cow<'event, [u8]>)>
pub fn pop(&mut self) -> Option<(Key<'_>, Cow<'event, [u8]>)>
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,
key: Key<'event>,
value: Cow<'event, [u8]>
) -> Option<Cow<'event, [u8]>>
pub fn set(
&mut self,
key: Key<'event>,
value: Cow<'event, [u8]>
) -> Option<Cow<'event, [u8]>>
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: &Key<'event>) -> Option<Cow<'event, [u8]>>
pub fn remove(&mut self, key: &Key<'event>) -> Option<Cow<'event, [u8]>>
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 implicit_newline(&mut self, on: bool)
pub fn 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_whitespace(&mut self, num: usize)
pub fn set_whitespace(&mut self, num: usize)
Sets the number of spaces before the start of a key value. By default, this is set to two. Set to 0 to disable adding whitespace before a key value.
sourcepub const fn whitespace(&self) -> usize
pub const fn whitespace(&self) -> usize
Returns the number of whitespace this section will insert before the beginning of a key.
Methods from Deref<Target = SectionBody<'event>>
sourcepub fn value(&self, key: &Key<'_>) -> Option<Cow<'event, [u8]>>
pub fn value(&self, key: &Key<'_>) -> Option<Cow<'event, [u8]>>
Retrieves the last matching value in a section with the given key. Returns None if the key was not found.
sourcepub fn value_as<T: TryFrom<Cow<'event, [u8]>>>(
&self,
key: &Key<'_>
) -> Result<T, Error<T::Error>>
pub fn value_as<T: TryFrom<Cow<'event, [u8]>>>(
&self,
key: &Key<'_>
) -> Result<T, Error<T::Error>>
Retrieves the last matching value in a section with the given key, and attempts to convert the value into the provided type.
Errors
Returns an error if the key was not found, or if the conversion failed.
sourcepub fn values(&self, key: &Key<'_>) -> Vec<Cow<'event, [u8]>>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn values(&self, key: &Key<'_>) -> Vec<Cow<'event, [u8]>>ⓘ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 values_as<T: TryFrom<Cow<'event, [u8]>>>(
&self,
key: &Key<'_>
) -> Result<Vec<T>, Error<T::Error>>
pub fn values_as<T: TryFrom<Cow<'event, [u8]>>>(
&self,
key: &Key<'_>
) -> Result<Vec<T>, Error<T::Error>>
Retrieves all values that have the provided key name. This may return an empty vec, which implies there was values with the provided key.
Errors
Returns an error if the conversion failed.
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: &Key<'_>) -> bool
pub fn contains_key(&self, key: &Key<'_>) -> bool
Checks if the section contains the provided key.
Trait Implementations
sourceimpl<'borrow, 'event> Debug for MutableSection<'borrow, 'event>
impl<'borrow, 'event> Debug for MutableSection<'borrow, 'event>
sourceimpl<'event> Deref for MutableSection<'_, 'event>
impl<'event> Deref for MutableSection<'_, 'event>
type Target = SectionBody<'event>
type Target = SectionBody<'event>
The resulting type after dereferencing.
sourceimpl<'borrow, 'event> Hash for MutableSection<'borrow, 'event>
impl<'borrow, 'event> Hash for MutableSection<'borrow, 'event>
sourceimpl<'borrow, 'event> Ord for MutableSection<'borrow, 'event>
impl<'borrow, 'event> Ord for MutableSection<'borrow, 'event>
sourceimpl<'borrow, 'event> PartialEq<MutableSection<'borrow, 'event>> for MutableSection<'borrow, 'event>
impl<'borrow, 'event> PartialEq<MutableSection<'borrow, 'event>> for MutableSection<'borrow, 'event>
sourcefn eq(&self, other: &MutableSection<'borrow, 'event>) -> bool
fn eq(&self, other: &MutableSection<'borrow, 'event>) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &MutableSection<'borrow, 'event>) -> bool
fn ne(&self, other: &MutableSection<'borrow, 'event>) -> bool
This method tests for !=
.
sourceimpl<'borrow, 'event> PartialOrd<MutableSection<'borrow, 'event>> for MutableSection<'borrow, 'event>
impl<'borrow, 'event> PartialOrd<MutableSection<'borrow, 'event>> for MutableSection<'borrow, 'event>
sourcefn partial_cmp(
&self,
other: &MutableSection<'borrow, 'event>
) -> Option<Ordering>
fn partial_cmp(
&self,
other: &MutableSection<'borrow, '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<'borrow, 'event> Eq for MutableSection<'borrow, 'event>
impl<'borrow, 'event> StructuralEq for MutableSection<'borrow, 'event>
impl<'borrow, 'event> StructuralPartialEq for MutableSection<'borrow, 'event>
Auto Trait Implementations
impl<'borrow, 'event> RefUnwindSafe for MutableSection<'borrow, 'event>
impl<'borrow, 'event> Send for MutableSection<'borrow, 'event>
impl<'borrow, 'event> Sync for MutableSection<'borrow, 'event>
impl<'borrow, 'event> Unpin for MutableSection<'borrow, 'event> where
'event: 'borrow,
impl<'borrow, 'event> !UnwindSafe for MutableSection<'borrow, '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