Skip to content

Commit d2e3f79

Browse files
Andreas Hindborgojeda
authored andcommitted
rust: str: implement AsRef<BStr> for [u8] and BStr
Implement `AsRef<BStr>` for `[u8]` and `BStr` so these can be used interchangeably for operations on `BStr`. Reviewed-by: Gary Guo <[email protected]> Tested-by: Daniel Almeida <[email protected]> Reviewed-by: Daniel Almeida <[email protected]> Signed-off-by: Andreas Hindborg <[email protected]> Reviewed-by: Fiona Behrens <[email protected]> Tested-by: Daniel Gomez <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 50a5ff0 commit d2e3f79

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

rust/kernel/str.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,18 @@ where
125125
}
126126
}
127127

128+
impl AsRef<BStr> for [u8] {
129+
fn as_ref(&self) -> &BStr {
130+
BStr::from_bytes(self)
131+
}
132+
}
133+
134+
impl AsRef<BStr> for BStr {
135+
fn as_ref(&self) -> &BStr {
136+
self
137+
}
138+
}
139+
128140
/// Creates a new [`BStr`] from a string literal.
129141
///
130142
/// `b_str!` converts the supplied string literal to byte string, so non-ASCII

0 commit comments

Comments
 (0)