aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Stepan Koltsov <stepan.koltsov@gmail.com> 2020-01-09 22:27:28 +0000
committerGravatar Sean McArthur <sean@seanmonstar.com> 2020-01-09 14:27:28 -0800
commit729bc7c2084a42fda2c62da6933951fa7ac875aa (patch)
treed2d8df2cc93c4fa5597926914dd19bdbcbfa290c
parent8695c08bcc5c51cf0832ef881eb5ccfe249e25ed (diff)
downloadbytes-729bc7c2084a42fda2c62da6933951fa7ac875aa.tar.gz
bytes-729bc7c2084a42fda2c62da6933951fa7ac875aa.tar.zst
bytes-729bc7c2084a42fda2c62da6933951fa7ac875aa.zip
Make Bytes::new const fn (#356)
-rw-r--r--src/bytes.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/bytes.rs b/src/bytes.rs
index 9e4dd91..93ab84b 100644
--- a/src/bytes.rs
+++ b/src/bytes.rs
@@ -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.