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 @@
11 use bstr::{BStr, ByteSlice};
22
33 /// Parse parts of a Git configuration key, like `remote.origin.url` or `core.bare`.
4−pub trait AsKey {
4+pub trait AsKey: Copy {
55 /// Return a parsed key reference, containing all relevant parts of a key.
66 /// For instance, `remote.origin.url` such key would yield access to `("remote", Some("origin"), "url")`
77 /// while `user.name` would yield `("user", None, "name")`.
@@ -22,7 +22,7 @@ mod impls { · 14 unmodified lines
2222
2323 use crate::key::{AsKey, KeyRef};
2424
25− impl AsKey for String {
25+ impl AsKey for &String {
2626 fn as_key(&self) -> KeyRef<'_> {
2727 self.try_as_key()
2828 .unwrap_or_else(|| panic!("'{self}' is not a valid configuration key"))
@@ -44,7 +44,7 @@ mod impls { · 15 unmodified lines
4444 }
4545 }
4646
47− impl AsKey for BString {
47+ impl AsKey for &BString {
4848 fn as_key(&self) -> KeyRef<'_> {
4949 self.try_as_key()
5050 .unwrap_or_else(|| panic!("'{self}' is not a valid configuration key"))