Skip to content

Commit 52fef46

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 831236c commit 52fef46

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
/// # Examples
@@ -121,7 +127,7 @@ impl Deref for BStr {
121127

122128
#[inline]
123129
fn deref(&self) -> &Self::Target {
124-
&self.0
130+
self.deref_const()
125131
}
126132
}
127133

0 commit comments

Comments
 (0)