mirror of
https://github.com/openharmony/third_party_rust_bytes.git
synced 2026-07-19 17:05:29 -04:00
Make Bytes::new const fn (#356)
This commit is contained in:
committed by
Sean McArthur
parent
4efc6a7663
commit
ec0825fe19
+11
-1
@@ -96,8 +96,18 @@ impl Bytes {
|
||||
/// assert_eq!(&b[..], b"");
|
||||
/// ```
|
||||
#[inline]
|
||||
#[cfg(not(all(loom, test)))]
|
||||
pub const fn new() -> Bytes {
|
||||
// Make it a named const to work around
|
||||
// "unsizing casts are not allowed in const fn"
|
||||
const EMPTY: &[u8] = &[];
|
||||
Bytes::from_static(EMPTY)
|
||||
}
|
||||
|
||||
#[cfg(all(loom, test))]
|
||||
pub fn new() -> Bytes {
|
||||
Bytes::from_static(b"")
|
||||
const EMPTY: &[u8] = &[];
|
||||
Bytes::from_static(EMPTY)
|
||||
}
|
||||
|
||||
/// Creates a new `Bytes` from a static slice.
|
||||
|
||||
Reference in New Issue
Block a user