History

fix!: allow `&str` to be parsed as key properly

Previously there were lifetime issue because the key needed the same lifetime as the underlying parsed file, which was hard to accomplish even with `&'static str'` as it really needed "&'static &'static str". However, this also means that owned keys can't be passed anymore.

Sebastian Thiel committed 7 months ago

Commit cf6c4031 parent ec66ceb1 file · +3 −3Browse files

Unified · Split

gix-config/src/key.rs+3−3
@@ -1,7 +1,7 @@
1use bstr::{BStr, ByteSlice};1use bstr::{BStr, ByteSlice};
2 2
3/// Parse parts of a Git configuration key, like `remote.origin.url` or `core.bare`.3/// Parse parts of a Git configuration key, like `remote.origin.url` or `core.bare`.
4pub trait AsKey {4pub trait AsKey: Copy {
5 /// Return a parsed key reference, containing all relevant parts of a key.5 /// Return a parsed key reference, containing all relevant parts of a key.
6 /// For instance, `remote.origin.url` such key would yield access to `("remote", Some("origin"), "url")`6 /// For instance, `remote.origin.url` such key would yield access to `("remote", Some("origin"), "url")`
7 /// while `user.name` would yield `("user", None, "name")`.7 /// while `user.name` would yield `("user", None, "name")`.
@@ -22,7 +22,7 @@ mod impls { · 14 unmodified lines
22 22
23 use crate::key::{AsKey, KeyRef};23 use crate::key::{AsKey, KeyRef};
24 24
25 impl AsKey for String {25 impl AsKey for &String {
26 fn as_key(&self) -> KeyRef<'_> {26 fn as_key(&self) -> KeyRef<'_> {
27 self.try_as_key()27 self.try_as_key()
28 .unwrap_or_else(|| panic!("'{self}' is not a valid configuration key"))28 .unwrap_or_else(|| panic!("'{self}' is not a valid configuration key"))
@@ -44,7 +44,7 @@ mod impls { · 15 unmodified lines
44 }44 }
45 }45 }
46 46
47 impl AsKey for BString {47 impl AsKey for &BString {
48 fn as_key(&self) -> KeyRef<'_> {48 fn as_key(&self) -> KeyRef<'_> {
49 self.try_as_key()49 self.try_as_key()
50 .unwrap_or_else(|| panic!("'{self}' is not a valid configuration key"))50 .unwrap_or_else(|| panic!("'{self}' is not a valid configuration key"))