Skip to content

Commit c1ae423

Browse files
committed
kernel_cmdline: Add CmdlineOwned alias for Cmdline<'static>
Signed-off-by: John Eckersberg <[email protected]>
1 parent 43061f0 commit c1ae423

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

crates/kernel_cmdline/src/bytes.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ use anyhow::Result;
1818
#[derive(Clone, Debug, Default)]
1919
pub struct Cmdline<'a>(Cow<'a, [u8]>);
2020

21+
/// An owned Cmdline. Alias for `Cmdline<'static>`.
22+
pub type CmdlineOwned = Cmdline<'static>;
23+
2124
impl<'a, T: AsRef<[u8]> + ?Sized> From<&'a T> for Cmdline<'a> {
2225
/// Creates a new `Cmdline` from any type that can be referenced as bytes.
2326
///
@@ -27,7 +30,7 @@ impl<'a, T: AsRef<[u8]> + ?Sized> From<&'a T> for Cmdline<'a> {
2730
}
2831
}
2932

30-
impl<'a> From<Vec<u8>> for Cmdline<'a> {
33+
impl From<Vec<u8>> for CmdlineOwned {
3134
/// Creates a new `Cmdline` from an owned `Vec<u8>`.
3235
fn from(input: Vec<u8>) -> Self {
3336
Self(Cow::Owned(input))
@@ -85,7 +88,7 @@ impl<'a> Cmdline<'a> {
8588
/// Creates a new empty owned `Cmdline`.
8689
///
8790
/// This is equivalent to `Cmdline::default()` but makes ownership explicit.
88-
pub fn new() -> Cmdline<'static> {
91+
pub fn new() -> CmdlineOwned {
8992
Cmdline::default()
9093
}
9194

@@ -670,8 +673,8 @@ mod tests {
670673
assert_eq!(kargs.iter().next(), None);
671674
assert!(kargs.is_owned());
672675

673-
// Verify we can store it in a 'static context
674-
let _static_kargs: Cmdline<'static> = Cmdline::new();
676+
// Verify we can store it in an owned ('static) context
677+
let _static_kargs: CmdlineOwned = Cmdline::new();
675678
}
676679

677680
#[test]

crates/kernel_cmdline/src/utf8.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ use anyhow::Result;
1717
#[derive(Clone, Debug, Default)]
1818
pub struct Cmdline<'a>(bytes::Cmdline<'a>);
1919

20+
/// An owned `Cmdline`. Alias for `Cmdline<'static>`.
21+
pub type CmdlineOwned = Cmdline<'static>;
22+
2023
impl<'a, T: AsRef<str> + ?Sized> From<&'a T> for Cmdline<'a> {
2124
/// Creates a new `Cmdline` from any type that can be referenced as `str`.
2225
///
@@ -26,7 +29,7 @@ impl<'a, T: AsRef<str> + ?Sized> From<&'a T> for Cmdline<'a> {
2629
}
2730
}
2831

29-
impl From<String> for Cmdline<'static> {
32+
impl From<String> for CmdlineOwned {
3033
/// Creates a new `Cmdline` from a `String`.
3134
///
3235
/// Takes ownership of input and maintains it for internal owned data.
@@ -72,7 +75,7 @@ impl<'a> Cmdline<'a> {
7275
/// Creates a new empty owned `Cmdline`.
7376
///
7477
/// This is equivalent to `Cmdline::default()` but makes ownership explicit.
75-
pub fn new() -> Cmdline<'static> {
78+
pub fn new() -> CmdlineOwned {
7679
Cmdline::default()
7780
}
7881

@@ -577,8 +580,8 @@ mod tests {
577580
assert_eq!(kargs.iter().next(), None);
578581
assert!(kargs.is_owned());
579582

580-
// Verify we can store it in a 'static context
581-
let _static_kargs: Cmdline<'static> = Cmdline::new();
583+
// Verify we can store it in an owned ('static) context
584+
let _static_kargs: CmdlineOwned = Cmdline::new();
582585
}
583586

584587
#[test]

0 commit comments

Comments
 (0)