Skip to content

Commit 0265531

Browse files
committed
rust: str: add method to be able to dereference BStr in a const context
Signed-off-by: Fabien Parent <fabien.parent@linaro.org>
1 parent 03ba7e7 commit 0265531

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

rust/kernel/str.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ impl BStr {
3535
// SAFETY: `BStr` is transparent to `[u8]`.
3636
unsafe { &*(bytes as *const [u8] as *const BStr) }
3737
}
38+
39+
/// Returns a reference to the inner [u8].
40+
#[inline]
41+
pub const fn deref_const(&self) -> &[u8] {
42+
&self.0
43+
}
3844
}
3945

4046
impl fmt::Display for BStr {
@@ -106,7 +112,7 @@ impl Deref for BStr {
106112

107113
#[inline]
108114
fn deref(&self) -> &Self::Target {
109-
&self.0
115+
self.deref_const()
110116
}
111117
}
112118

0 commit comments

Comments
 (0)