Skip to content

Commit 59aea9e

Browse files
andrewtjcarllerche
authored andcommitted
Make Bytes::from_static a const fn (#311)
Rust versions bumped to the minimum needed for const slice len.
1 parent 9a10add commit 59aea9e

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

azure-pipelines.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- template: ci/azure-test-stable.yml
2121
parameters:
2222
name: minrust
23-
rust_version: 1.36.0
23+
rust_version: 1.39.0
2424
cmd: check
2525

2626
# Stable
@@ -37,7 +37,7 @@ jobs:
3737
parameters:
3838
name: nightly
3939
# Pin nightly to avoid being impacted by breakage
40-
rust_version: nightly-2019-07-17
40+
rust_version: nightly-2019-09-25
4141
benches: true
4242

4343
# Run tests on some extra platforms

src/bytes.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,17 @@ impl Bytes {
114114
/// assert_eq!(&b[..], b"hello");
115115
/// ```
116116
#[inline]
117+
#[cfg(not(all(loom, test)))]
118+
pub const fn from_static(bytes: &'static [u8]) -> Bytes {
119+
Bytes {
120+
ptr: bytes.as_ptr(),
121+
len: bytes.len(),
122+
data: AtomicPtr::new(ptr::null_mut()),
123+
vtable: &STATIC_VTABLE,
124+
}
125+
}
126+
127+
#[cfg(all(loom, test))]
117128
pub fn from_static(bytes: &'static [u8]) -> Bytes {
118129
Bytes {
119130
ptr: bytes.as_ptr(),
@@ -732,7 +743,7 @@ impl fmt::Debug for Vtable {
732743

733744
// ===== impl StaticVtable =====
734745

735-
static STATIC_VTABLE: Vtable = Vtable {
746+
const STATIC_VTABLE: Vtable = Vtable {
736747
clone: static_clone,
737748
drop: static_drop,
738749
};

0 commit comments

Comments
 (0)