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
242242 }
243243
244244 impl<'event> Deref for SectionMut<'_, 'event> {
245− type Target = file::section::Body<'event>;
245+ type Target = file::Section<'event>;
246246
247247 fn deref(&self) -> &Self::Target {
248248 self.section
git-config/src/file/mutable/value.rs+11−0
@@ -3,6 +3,7 @@ use std::borrow::Cow; · 2 unmodified lines
33 use bstr::BStr;
44
55 use crate::{
6+ file,
67 file::{mutable::section::SectionMut, Index, Size},
78 lookup,
89 parse::section,
@@ -49,4 +50,14 @@ impl<'borrow, 'lookup, 'event> ValueMut<'borrow, 'lookup, 'event> { · 40 unmodified lines
4950 self.size = Size(0);
5051 }
5152 }
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+ }
5263 }