History

unclutter lifetime declarations (#331)

Only use what we actually need.

Sebastian Thiel committed 4 years ago

Commit e571fdb1 parent 183c7ae5 files · +57 −57Browse files

Unified · Split

5 files
  1. git-config/src/file/access/low_level/mutating.rs +22 −22
  2. git-config/src/file/access/low_level/read_only.rs +6 −6
  3. git-config/src/file/access/raw.rs +16 −16
  4. git-config/src/file/utils.rs +5 −5
  5. git-config/src/fs.rs +8 −8
git-config/src/file/access/low_level/mutating.rs+22−22
@@ -9,13 +9,13 @@ use crate::{ · 8 unmodified lines
9};9};
10 10
11/// Mutating low-level access methods.11/// Mutating low-level access methods.
12impl<'a> File<'a> {12impl<'event> File<'event> {
13 /// Returns an mutable section reference.13 /// Returns an mutable section reference.
14 pub fn section_mut<'lookup>(14 pub fn section_mut<'a>(
15 &mut self,15 &'a mut self,
16 section_name: &'lookup str,16 section_name: &str,
17 subsection_name: Option<&'lookup str>,17 subsection_name: Option<&str>,
18 ) -> Result<MutableSection<'_, 'a>, lookup::existing::Error> {18 ) -> Result<MutableSection<'a, 'event>, lookup::existing::Error> {
19 let section_ids = self.section_ids_by_name_and_subname(section_name, subsection_name)?;19 let section_ids = self.section_ids_by_name_and_subname(section_name, subsection_name)?;
20 let id = section_ids.last().expect("BUG: Section lookup vec was empty");20 let id = section_ids.last().expect("BUG: Section lookup vec was empty");
21 Ok(MutableSection::new(21 Ok(MutableSection::new(
@@ -56,9 +56,9 @@ impl<'a> File<'a> { · 34 unmodified lines
56 /// ```56 /// ```
57 pub fn new_section(57 pub fn new_section(
58 &mut self,58 &mut self,
59 section_name: impl Into<Cow<'a, str>>,59 section_name: impl Into<Cow<'event, str>>,
60 subsection_name: impl Into<Option<Cow<'a, str>>>,60 subsection_name: impl Into<Option<Cow<'event, str>>>,
61 ) -> MutableSection<'_, 'a> {61 ) -> MutableSection<'_, 'event> {
62 let mut section = self.push_section(section_name, subsection_name, SectionBody::default());62 let mut section = self.push_section(section_name, subsection_name, SectionBody::default());
63 section.push_newline();63 section.push_newline();
64 section64 section
@@ -99,11 +99,11 @@ impl<'a> File<'a> { · 34 unmodified lines
99 /// let events = git_config.remove_section("hello", Some("world".into()));99 /// let events = git_config.remove_section("hello", Some("world".into()));
100 /// assert_eq!(git_config.to_string(), "[hello \"world\"]\n some-value = 4\n");100 /// assert_eq!(git_config.to_string(), "[hello \"world\"]\n some-value = 4\n");
101 /// ```101 /// ```
102 pub fn remove_section<'lookup>(102 pub fn remove_section<'a>(
103 &mut self,103 &mut self,
104 section_name: &'lookup str,104 section_name: &str,
105 subsection_name: impl Into<Option<&'lookup str>>,105 subsection_name: impl Into<Option<&'a str>>,
106 ) -> Option<SectionBody<'a>> {106 ) -> Option<SectionBody<'event>> {
107 let id = self107 let id = self
108 .section_ids_by_name_and_subname(section_name, subsection_name.into())108 .section_ids_by_name_and_subname(section_name, subsection_name.into())
109 .ok()?109 .ok()?
@@ -121,10 +121,10 @@ impl<'a> File<'a> { · 11 unmodified lines
121 /// to it.121 /// to it.
122 pub fn push_section(122 pub fn push_section(
123 &mut self,123 &mut self,
124 section_name: impl Into<Cow<'a, str>>,124 section_name: impl Into<Cow<'event, str>>,
125 subsection_name: impl Into<Option<Cow<'a, str>>>,125 subsection_name: impl Into<Option<Cow<'event, str>>>,
126 section: SectionBody<'a>,126 section: SectionBody<'event>,
127 ) -> MutableSection<'_, 'a> {127 ) -> MutableSection<'_, 'event> {
128 let subsection_name = subsection_name.into().map(into_cow_bstr);128 let subsection_name = subsection_name.into().map(into_cow_bstr);
129 self.push_section_internal(129 self.push_section_internal(
130 section::Header {130 section::Header {
@@ -137,12 +137,12 @@ impl<'a> File<'a> { · 6 unmodified lines
137 }137 }
138 138
139 /// Renames a section, modifying the last matching section.139 /// Renames a section, modifying the last matching section.
140 pub fn rename_section<'lookup>(140 pub fn rename_section<'a>(
141 &mut self,141 &mut self,
142 section_name: &'lookup str,142 section_name: &str,
143 subsection_name: impl Into<Option<&'lookup str>>,143 subsection_name: impl Into<Option<&'a str>>,
144 new_section_name: impl Into<section::Name<'a>>,144 new_section_name: impl Into<section::Name<'event>>,
145 new_subsection_name: impl Into<Option<Cow<'a, str>>>,145 new_subsection_name: impl Into<Option<Cow<'event, str>>>,
146 ) -> Result<(), lookup::existing::Error> {146 ) -> Result<(), lookup::existing::Error> {
147 let id = self.section_ids_by_name_and_subname(section_name, subsection_name.into())?;147 let id = self.section_ids_by_name_and_subname(section_name, subsection_name.into())?;
148 let id = id148 let id = id
git-config/src/file/access/low_level/read_only.rs+6−6
@@ -114,10 +114,10 @@ impl<'event> File<'event> { · 113 unmodified lines
114 }114 }
115 115
116 /// Returns an immutable section reference.116 /// Returns an immutable section reference.
117 pub fn section<'lookup>(117 pub fn section(
118 &mut self,118 &mut self,
119 section_name: &'lookup str,119 section_name: &str,
120 subsection_name: Option<&'lookup str>,120 subsection_name: Option<&str>,
121 ) -> Result<&SectionBody<'event>, lookup::existing::Error> {121 ) -> Result<&SectionBody<'event>, lookup::existing::Error> {
122 let section_ids = self.section_ids_by_name_and_subname(section_name, subsection_name)?;122 let section_ids = self.section_ids_by_name_and_subname(section_name, subsection_name)?;
123 let id = section_ids.last().expect("BUG: Section lookup vec was empty");123 let id = section_ids.last().expect("BUG: Section lookup vec was empty");
@@ -158,7 +158,7 @@ impl<'event> File<'event> { · 34 unmodified lines
158 /// assert_eq!(git_config.sections_by_name("core").len(), 3);158 /// assert_eq!(git_config.sections_by_name("core").len(), 3);
159 /// ```159 /// ```
160 #[must_use]160 #[must_use]
161 pub fn sections_by_name<'lookup>(&self, section_name: &'lookup str) -> Vec<&SectionBody<'event>> {161 pub fn sections_by_name(&self, section_name: &str) -> Vec<&SectionBody<'event>> {
162 self.section_ids_by_name(section_name)162 self.section_ids_by_name(section_name)
163 .unwrap_or_default()163 .unwrap_or_default()
164 .into_iter()164 .into_iter()
@@ -216,9 +216,9 @@ impl<'event> File<'event> { · 51 unmodified lines
216 /// }216 /// }
217 /// }217 /// }
218 /// ```218 /// ```
219 pub fn sections_by_name_with_header<'lookup>(219 pub fn sections_by_name_with_header(
220 &self,220 &self,
221 section_name: &'lookup str,221 section_name: &str,
222 ) -> Vec<(&section::Header<'event>, &SectionBody<'event>)> {222 ) -> Vec<(&section::Header<'event>, &SectionBody<'event>)> {
223 self.section_ids_by_name(section_name)223 self.section_ids_by_name(section_name)
224 .unwrap_or_default()224 .unwrap_or_default()
git-config/src/file/access/raw.rs+16−16
@@ -12,17 +12,17 @@ use crate::{ · 11 unmodified lines
12///12///
13/// These functions are the raw value API. Instead of returning Rust structures,13/// These functions are the raw value API. Instead of returning Rust structures,
14/// these functions return bytes which may or may not be owned.14/// these functions return bytes which may or may not be owned.
15impl<'a> File<'a> {15impl<'event> File<'event> {
16 /// Returns an uninterpreted value given a section, an optional subsection16 /// Returns an uninterpreted value given a section, an optional subsection
17 /// and key.17 /// and key.
18 ///18 ///
19 /// Consider [`Self::raw_multi_value`] if you want to get all values of19 /// Consider [`Self::raw_multi_value`] if you want to get all values of
20 /// a multivar instead.20 /// a multivar instead.
21 pub fn raw_value<'lookup>(21 pub fn raw_value(
22 &self,22 &self,
23 section_name: &'lookup str,23 section_name: &str,
24 subsection_name: Option<&'lookup str>,24 subsection_name: Option<&str>,
25 key: &'lookup str,25 key: &str,
26 ) -> Result<Cow<'_, BStr>, lookup::existing::Error> {26 ) -> Result<Cow<'_, BStr>, lookup::existing::Error> {
27 // Note: cannot wrap around the raw_multi_value method because we need27 // Note: cannot wrap around the raw_multi_value method because we need
28 // to guarantee that the highest section id is used (so that we follow28 // to guarantee that the highest section id is used (so that we follow
@@ -56,7 +56,7 @@ impl<'a> File<'a> { · 27 unmodified lines
56 section_name: &'lookup str,56 section_name: &'lookup str,
57 subsection_name: Option<&'lookup str>,57 subsection_name: Option<&'lookup str>,
58 key: &'lookup str,58 key: &'lookup str,
59 ) -> Result<MutableValue<'_, 'lookup, 'a>, lookup::existing::Error> {59 ) -> Result<MutableValue<'_, 'lookup, 'event>, lookup::existing::Error> {
60 let section_ids = self.section_ids_by_name_and_subname(section_name, subsection_name)?;60 let section_ids = self.section_ids_by_name_and_subname(section_name, subsection_name)?;
61 let key = section::Key(Cow::<BStr>::Borrowed(key.into()));61 let key = section::Key(Cow::<BStr>::Borrowed(key.into()));
62 62
@@ -222,7 +222,7 @@ impl<'a> File<'a> { · 159 unmodified lines
222 section_name: &'lookup str,222 section_name: &'lookup str,
223 subsection_name: Option<&'lookup str>,223 subsection_name: Option<&'lookup str>,
224 key: &'lookup str,224 key: &'lookup str,
225 ) -> Result<MutableMultiValue<'_, 'lookup, 'a>, lookup::existing::Error> {225 ) -> Result<MutableMultiValue<'_, 'lookup, 'event>, lookup::existing::Error> {
226 let section_ids = self.section_ids_by_name_and_subname(section_name, subsection_name)?;226 let section_ids = self.section_ids_by_name_and_subname(section_name, subsection_name)?;
227 let key = section::Key(Cow::<BStr>::Borrowed(key.into()));227 let key = section::Key(Cow::<BStr>::Borrowed(key.into()));
228 228
@@ -296,11 +296,11 @@ impl<'a> File<'a> { · 67 unmodified lines
296 /// assert_eq!(git_config.raw_value("core", None, "a")?, Cow::<BStr>::Borrowed("e".into()));296 /// assert_eq!(git_config.raw_value("core", None, "a")?, Cow::<BStr>::Borrowed("e".into()));
297 /// # Ok::<(), Box<dyn std::error::Error>>(())297 /// # Ok::<(), Box<dyn std::error::Error>>(())
298 /// ```298 /// ```
299 pub fn set_raw_value<'lookup>(299 pub fn set_raw_value(
300 &mut self,300 &mut self,
301 section_name: &'lookup str,301 section_name: &str,
302 subsection_name: Option<&'lookup str>,302 subsection_name: Option<&str>,
303 key: &'lookup str,303 key: &str,
304 new_value: BString,304 new_value: BString,
305 ) -> Result<(), lookup::existing::Error> {305 ) -> Result<(), lookup::existing::Error> {
306 self.raw_value_mut(section_name, subsection_name, key)306 self.raw_value_mut(section_name, subsection_name, key)
@@ -393,12 +393,12 @@ impl<'a> File<'a> { · 86 unmodified lines
393 /// ```393 /// ```
394 ///394 ///
395 /// [`raw_multi_value_mut`]: Self::raw_multi_value_mut395 /// [`raw_multi_value_mut`]: Self::raw_multi_value_mut
396 pub fn set_raw_multi_value<'lookup>(396 pub fn set_raw_multi_value(
397 &mut self,397 &mut self,
398 section_name: &'lookup str,398 section_name: &str,
399 subsection_name: Option<&'lookup str>,399 subsection_name: Option<&str>,
400 key: &'lookup str,400 key: &str,
401 new_values: impl Iterator<Item = Cow<'a, BStr>>,401 new_values: impl Iterator<Item = Cow<'event, BStr>>,
402 ) -> Result<(), lookup::existing::Error> {402 ) -> Result<(), lookup::existing::Error> {
403 self.raw_multi_value_mut(section_name, subsection_name, key)403 self.raw_multi_value_mut(section_name, subsection_name, key)
404 .map(|mut v| v.set_values(new_values))404 .map(|mut v| v.set_values(new_values))
git-config/src/file/utils.rs+5−5
@@ -57,10 +57,10 @@ impl<'event> File<'event> { · 56 unmodified lines
57 }57 }
58 58
59 /// Returns the mapping between section and subsection name to section ids.59 /// Returns the mapping between section and subsection name to section ids.
60 pub(crate) fn section_ids_by_name_and_subname<'lookup>(60 pub(crate) fn section_ids_by_name_and_subname<'a>(
61 &self,61 &self,
62 section_name: impl Into<section::Name<'lookup>>,62 section_name: impl Into<section::Name<'a>>,
63 subsection_name: Option<&'lookup str>,63 subsection_name: Option<&str>,
64 ) -> Result<Vec<SectionId>, lookup::existing::Error> {64 ) -> Result<Vec<SectionId>, lookup::existing::Error> {
65 let section_name = section_name.into();65 let section_name = section_name.into();
66 let section_ids = self66 let section_ids = self
@@ -92,9 +92,9 @@ impl<'event> File<'event> { · 25 unmodified lines
92 .ok_or(lookup::existing::Error::SubSectionMissing)92 .ok_or(lookup::existing::Error::SubSectionMissing)
93 }93 }
94 94
95 pub(crate) fn section_ids_by_name<'lookup>(95 pub(crate) fn section_ids_by_name<'a>(
96 &self,96 &self,
97 section_name: impl Into<section::Name<'lookup>>,97 section_name: impl Into<section::Name<'a>>,
98 ) -> Result<Vec<SectionId>, lookup::existing::Error> {98 ) -> Result<Vec<SectionId>, lookup::existing::Error> {
99 let section_name = section_name.into();99 let section_name = section_name.into();
100 self.section_lookup_tree100 self.section_lookup_tree
git-config/src/fs.rs+8−8
@@ -179,11 +179,11 @@ impl<'a> Config<'a> { · 178 unmodified lines
179 None179 None
180 }180 }
181 181
182 pub fn try_value<'lookup, T: TryFrom<Cow<'a, BStr>>>(182 pub fn try_value<T: TryFrom<Cow<'a, BStr>>>(
183 &'a self,183 &'a self,
184 section_name: &'lookup str,184 section_name: &str,
185 subsection_name: Option<&'lookup str>,185 subsection_name: Option<&str>,
186 key: &'lookup str,186 key: &str,
187 ) -> Result<Option<T>, lookup::Error<T::Error>> {187 ) -> Result<Option<T>, lookup::Error<T::Error>> {
188 self.try_value_with_source(section_name, subsection_name, key)188 self.try_value_with_source(section_name, subsection_name, key)
189 .map(|res| res.map(|(value, _)| value))189 .map(|res| res.map(|(value, _)| value))
@@ -193,11 +193,11 @@ impl<'a> Config<'a> { · 3 unmodified lines
193 /// if the key was not found. On a successful parse, the value will be193 /// if the key was not found. On a successful parse, the value will be
194 /// returned as well as the source location. This respects the priority of194 /// returned as well as the source location. This respects the priority of
195 /// the various configuration files.195 /// the various configuration files.
196 pub fn try_value_with_source<'lookup, T: TryFrom<Cow<'a, BStr>>>(196 pub fn try_value_with_source<T: TryFrom<Cow<'a, BStr>>>(
197 &'a self,197 &'a self,
198 section_name: &'lookup str,198 section_name: &str,
199 subsection_name: Option<&'lookup str>,199 subsection_name: Option<&str>,
200 key: &'lookup str,200 key: &str,
201 ) -> Result<Option<(T, ConfigSource)>, lookup::Error<T::Error>> {201 ) -> Result<Option<(T, ConfigSource)>, lookup::Error<T::Error>> {
202 let mapping = self.mapping();202 let mapping = self.mapping();
203 203

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t