@@ -72,26 +72,27 @@ impl<'a> Cmdline<'a> {
72
72
///
73
73
/// Returns the first parameter matching the given key, or `None` if not found.
74
74
/// Key comparison treats dashes and underscores as equivalent.
75
- pub fn find ( & ' a self , key : impl AsRef < str > ) -> Option < Parameter < ' a > > {
75
+ pub fn find < T : AsRef < str > + ? Sized > ( & ' a self , key : & T ) -> Option < Parameter < ' a > > {
76
76
let key = ParameterKey :: from ( key. as_ref ( ) ) ;
77
77
self . iter ( ) . find ( |p| p. key ( ) == key)
78
78
}
79
79
80
80
/// Find all kernel arguments starting with the given UTF-8 prefix.
81
81
///
82
82
/// This is a variant of [`Self::find`].
83
- pub fn find_all_starting_with (
83
+ pub fn find_all_starting_with < T : AsRef < str > + ? Sized > (
84
84
& ' a self ,
85
- prefix : & ' a str ,
85
+ prefix : & ' a T ,
86
86
) -> impl Iterator < Item = Parameter < ' a > > + ' a {
87
- self . iter ( ) . filter ( move |p| p. key ( ) . starts_with ( prefix) )
87
+ self . iter ( )
88
+ . filter ( move |p| p. key ( ) . starts_with ( prefix. as_ref ( ) ) )
88
89
}
89
90
90
91
/// Locate the value of the kernel argument with the given key name.
91
92
///
92
93
/// Returns the first value matching the given key, or `None` if not found.
93
94
/// Key comparison treats dashes and underscores as equivalent.
94
- pub fn value_of ( & ' a self , key : impl AsRef < str > ) -> Option < & ' a str > {
95
+ pub fn value_of < T : AsRef < str > + ? Sized > ( & ' a self , key : & T ) -> Option < & ' a str > {
95
96
self . 0 . value_of ( key. as_ref ( ) . as_bytes ( ) ) . map ( |v| {
96
97
// SAFETY: We know this is valid UTF-8 since we only
97
98
// construct the underlying `bytes` from valid UTF-8
@@ -102,7 +103,7 @@ impl<'a> Cmdline<'a> {
102
103
/// Find the value of the kernel argument with the provided name, which must be present.
103
104
///
104
105
/// Otherwise the same as [`Self::value_of`].
105
- pub fn require_value_of ( & ' a self , key : impl AsRef < str > ) -> Result < & ' a str > {
106
+ pub fn require_value_of < T : AsRef < str > + ? Sized > ( & ' a self , key : & T ) -> Result < & ' a str > {
106
107
let key = key. as_ref ( ) ;
107
108
self . value_of ( key)
108
109
. ok_or_else ( || anyhow:: anyhow!( "Failed to find kernel argument '{key}'" ) )
@@ -159,9 +160,9 @@ impl<'a> ParameterKey<'a> {
159
160
}
160
161
}
161
162
162
- impl < ' a > From < & ' a str > for ParameterKey < ' a > {
163
- fn from ( input : & ' a str ) -> Self {
164
- Self ( bytes:: ParameterKey ( input. as_bytes ( ) ) )
163
+ impl < ' a , T : AsRef < str > + ? Sized > From < & ' a T > for ParameterKey < ' a > {
164
+ fn from ( input : & ' a T ) -> Self {
165
+ Self ( bytes:: ParameterKey ( input. as_ref ( ) . as_bytes ( ) ) )
165
166
}
166
167
}
167
168
@@ -197,8 +198,8 @@ impl<'a> Parameter<'a> {
197
198
///
198
199
/// Any remaining characters not consumed from the input are
199
200
/// returned as the second tuple item.
200
- pub fn parse ( input : & ' a str ) -> ( Option < Self > , & ' a str ) {
201
- let ( bytes, rest) = bytes:: Parameter :: parse ( input. as_bytes ( ) ) ;
201
+ pub fn parse < T : AsRef < str > + ? Sized > ( input : & ' a T ) -> ( Option < Self > , & ' a str ) {
202
+ let ( bytes, rest) = bytes:: Parameter :: parse ( input. as_ref ( ) . as_bytes ( ) ) ;
202
203
203
204
// SAFETY: we know this is valid UTF-8 since input is &str,
204
205
// and `rest` is a subslice of that &str which was split on
0 commit comments