Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Bytes::from_static a const fn? #311

Merged
merged 1 commit into from Nov 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions azure-pipelines.yml
Expand Up @@ -20,7 +20,7 @@ jobs:
- template: ci/azure-test-stable.yml
parameters:
name: minrust
rust_version: 1.36.0
rust_version: 1.39.0
cmd: check

# Stable
Expand All @@ -37,7 +37,7 @@ jobs:
parameters:
name: nightly
# Pin nightly to avoid being impacted by breakage
rust_version: nightly-2019-07-17
rust_version: nightly-2019-09-25
benches: true

# Run tests on some extra platforms
Expand Down
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