Skip to content

Commit

Permalink
Make Bytes::from_static a const fn
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtj committed Nov 13, 2019
1 parent 9a10add commit 336c015
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/bytes.rs
Expand Up @@ -114,6 +114,17 @@ impl Bytes {
/// assert_eq!(&b[..], b"hello");
/// ```
#[inline]
#[cfg(not(all(loom, test)))]
pub const fn from_static(bytes: &'static [u8]) -> Bytes {
Bytes {
ptr: bytes.as_ptr(),
len: bytes.len(),
data: AtomicPtr::new(ptr::null_mut()),
vtable: &STATIC_VTABLE,
}
}

#[cfg(all(loom, test))]
pub fn from_static(bytes: &'static [u8]) -> Bytes {
Bytes {
ptr: bytes.as_ptr(),
Expand Down Expand Up @@ -732,7 +743,7 @@ impl fmt::Debug for Vtable {

// ===== impl StaticVtable =====

static STATIC_VTABLE: Vtable = Vtable {
const STATIC_VTABLE: Vtable = Vtable {
clone: static_clone,
drop: static_drop,
};
Expand Down

0 comments on commit 336c015

Please sign in to comment.