Struct git_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§

source§

impl<'a, 'event> SectionMut<'a, 'event>

Mutating methods.

source

pub fn push<'b>(&mut self, key: Key<'event>, value: Option<&'b BStr>) -> &mut Self

Adds an entry to the end of this section name key 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.

source

pub fn push_with_comment<'b, 'c>( &mut self, key: Key<'event>, value: Option<&'b BStr>, comment: impl Into<&'c BStr> ) -> &mut Self

Adds an entry to the end of this section name key 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.

source

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.

source

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.

source

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.

source

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.

source

pub fn newline(&self) -> &BStr

Return the newline used when calling push_newline().

source

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.

source

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.

source

pub fn leading_whitespace(&self) -> Option<&BStr>

Returns the whitespace this section will insert before the beginning of a key, if any.

source

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>>§

source

pub fn header(&self) -> &Header<'a>

Return our header.

source

pub fn id(&self) -> SectionId

Return the unique id of the section, for use with the *_by_id() family of methods in git_config::File.

source

pub fn body(&self) -> &Body<'a>

Return our body, containing all keys and values.

source

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.

source

pub fn write_to(&self, out: impl Write) -> Result<()>

Stream ourselves to the given out, in order to reproduce this section mostly losslessly as it was parsed.

source

pub fn meta(&self) -> &Metadata

Return additional information about this sections origin.

Methods from Deref<Target = Body<'a>>§

source

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.

source

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

source

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.

source

pub fn keys(&self) -> impl Iterator<Item = &Key<'event>>

Returns an iterator visiting all keys in order.

source

pub fn contains_key(&self, key: impl AsRef<str>) -> bool

Returns true if the section contains the provided key.

source

pub fn num_values(&self) -> usize

Returns the number of values in the section.

source

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<'a, 'event> Debug for SectionMut<'a, 'event>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'event> Deref for SectionMut<'_, 'event>

§

type Target = Section<'event>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<'a, 'event> Hash for SectionMut<'a, 'event>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<'a, 'event> Ord for SectionMut<'a, 'event>

source§

fn cmp(&self, other: &SectionMut<'a, 'event>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl<'a, 'event> PartialEq<SectionMut<'a, 'event>> for SectionMut<'a, 'event>

source§

fn eq(&self, other: &SectionMut<'a, 'event>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, 'event> PartialOrd<SectionMut<'a, 'event>> for SectionMut<'a, 'event>

source§

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 · source§

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 · source§

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
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<'a, 'event> Eq for SectionMut<'a, 'event>

source§

impl<'a, 'event> StructuralEq for SectionMut<'a, 'event>

source§

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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.