Skip to content

Commit 18ebcd9

Browse files
committed
ByteStr::as_[mut_]byte_str
1 parent 4e5ce74 commit 18ebcd9

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

library/core/src/bstr/mod.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,30 @@ impl ByteStr {
6868
ByteStr::from_bytes(bytes.as_ref())
6969
}
7070

71+
/// Returns the same string as `&ByteStr`.
72+
///
73+
/// This method is redundant when used directly on `&ByteStr`, but
74+
/// it helps dereferencing other `ByteString`-like types,
75+
/// for example `Box<ByteStr>` or `Arc<ByteStr>`.
76+
#[inline]
77+
// #[unstable(feature = "str_as_str", issue = "130366")]
78+
#[unstable(feature = "bstr", issue = "134915")]
79+
pub const fn as_byte_str(&self) -> &ByteStr {
80+
self
81+
}
82+
83+
/// Returns the same string as `&mut ByteStr`.
84+
///
85+
/// This method is redundant when used directly on `&mut ByteStr`, but
86+
/// it helps dereferencing other `ByteString`-like types,
87+
/// for example `Box<ByteStr>` or `MutexGuard<ByteStr>`.
88+
#[inline]
89+
// #[unstable(feature = "str_as_str", issue = "130366")]
90+
#[unstable(feature = "bstr", issue = "134915")]
91+
pub const fn as_mut_byte_str(&mut self) -> &mut ByteStr {
92+
self
93+
}
94+
7195
#[doc(hidden)]
7296
#[unstable(feature = "bstr_internals", issue = "none")]
7397
#[inline]

0 commit comments

Comments
 (0)