mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-25 00:00:22 +02:00
Make Bytes::from_static a const fn (#311)
Rust versions bumped to the minimum needed for const slice len.
This commit is contained in:
committed by
Carl Lerche
parent
9a10addb44
commit
59aea9e871
+2
-2
@@ -20,7 +20,7 @@ jobs:
|
|||||||
- template: ci/azure-test-stable.yml
|
- template: ci/azure-test-stable.yml
|
||||||
parameters:
|
parameters:
|
||||||
name: minrust
|
name: minrust
|
||||||
rust_version: 1.36.0
|
rust_version: 1.39.0
|
||||||
cmd: check
|
cmd: check
|
||||||
|
|
||||||
# Stable
|
# Stable
|
||||||
@@ -37,7 +37,7 @@ jobs:
|
|||||||
parameters:
|
parameters:
|
||||||
name: nightly
|
name: nightly
|
||||||
# Pin nightly to avoid being impacted by breakage
|
# Pin nightly to avoid being impacted by breakage
|
||||||
rust_version: nightly-2019-07-17
|
rust_version: nightly-2019-09-25
|
||||||
benches: true
|
benches: true
|
||||||
|
|
||||||
# Run tests on some extra platforms
|
# Run tests on some extra platforms
|
||||||
|
|||||||
+12
-1
@@ -114,6 +114,17 @@ impl Bytes {
|
|||||||
/// assert_eq!(&b[..], b"hello");
|
/// assert_eq!(&b[..], b"hello");
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[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 {
|
pub fn from_static(bytes: &'static [u8]) -> Bytes {
|
||||||
Bytes {
|
Bytes {
|
||||||
ptr: bytes.as_ptr(),
|
ptr: bytes.as_ptr(),
|
||||||
@@ -732,7 +743,7 @@ impl fmt::Debug for Vtable {
|
|||||||
|
|
||||||
// ===== impl StaticVtable =====
|
// ===== impl StaticVtable =====
|
||||||
|
|
||||||
static STATIC_VTABLE: Vtable = Vtable {
|
const STATIC_VTABLE: Vtable = Vtable {
|
||||||
clone: static_clone,
|
clone: static_clone,
|
||||||
drop: static_drop,
|
drop: static_drop,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user