History

feat: `file::ValueMut::(section|into_section_mut)()` to go from value to the owning section. (#331)

This can be useful if the value was obtained using `raw_value_mut()`.

Sebastian Thiel committed 4 years ago

Commit fff08841 parent d9eb34c2 files · +12 −1Browse files

Unified · Split

2 files
  1. git-config/src/file/mutable/section.rs +1 −1
  2. git-config/src/file/mutable/value.rs +11 −0
git-config/src/file/mutable/section.rs+1−1
@@ -242,7 +242,7 @@ impl<'a, 'event> SectionMut<'a, 'event> { · 241 unmodified lines
242}242}
243 243
244impl<'event> Deref for SectionMut<'_, 'event> {244impl<'event> Deref for SectionMut<'_, 'event> {
245 type Target = file::section::Body<'event>;245 type Target = file::Section<'event>;
246 246
247 fn deref(&self) -> &Self::Target {247 fn deref(&self) -> &Self::Target {
248 self.section248 self.section
git-config/src/file/mutable/value.rs+11−0
@@ -3,6 +3,7 @@ use std::borrow::Cow; · 2 unmodified lines
3use bstr::BStr;3use bstr::BStr;
4 4
5use crate::{5use crate::{
6 file,
6 file::{mutable::section::SectionMut, Index, Size},7 file::{mutable::section::SectionMut, Index, Size},
7 lookup,8 lookup,
8 parse::section,9 parse::section,
@@ -49,4 +50,14 @@ impl<'borrow, 'lookup, 'event> ValueMut<'borrow, 'lookup, 'event> { · 40 unmodified lines
49 self.size = Size(0);50 self.size = Size(0);
50 }51 }
51 }52 }
53
54 /// Return the section containing the value.
55 pub fn section(&self) -> &file::Section<'event> {
56 &self.section
57 }
58
59 /// Convert this value into its owning mutable section.
60 pub fn into_section_mut(self) -> file::SectionMut<'borrow, 'event> {
61 self.section
62 }
52}63}