Skip to content

Commit a49ebe0

Browse files
Fabojannau
authored andcommitted
rust: str: allow dereferencing BStr in a const ctx
impl Deref doesn't work in const context. Add a function that is similar to implementing `deref` but that can be used in `const` context. Signed-off-by: Fabien Parent <fabien.parent@linaro.org>
1 parent 2f1a65f commit a49ebe0

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
@@ -32,6 +32,12 @@ impl BStr {
3232
unsafe { &*(bytes as *const [u8] as *const BStr) }
3333
}
3434

35+
/// Returns a reference to the inner [u8].
36+
#[inline]
37+
pub const fn deref_const(&self) -> &[u8] {
38+
&self.0
39+
}
40+
3541
/// Strip a prefix from `self`. Delegates to [`slice::strip_prefix`].
3642
///
3743
/// # Example
@@ -120,7 +126,7 @@ impl Deref for BStr {
120126

121127
#[inline]
122128
fn deref(&self) -> &Self::Target {
123-
&self.0
129+
self.deref_const()
124130
}
125131
}
126132

0 commit comments

Comments
 (0)