Skip to content

Commit cf6c403

Browse files
committed
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.
1 parent ec66ceb commit cf6c403

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

gix-config/src/key.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {
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 {
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"))

0 commit comments

Comments
 (0)