Skip to content

Commit 8ed9fef

Browse files
committed
feat(experimental): allow access to unzeroed byteview
1 parent d360a98 commit 8ed9fef

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "byteview"
33
description = "Thin, immutable zero-copy slice type"
44
license = "MIT OR Apache-2.0"
5-
version = "0.6.1"
5+
version = "0.7.0"
66
edition = "2021"
77
rust-version = "1.74"
88
readme = "README.md"

src/byteview.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl std::cmp::PartialEq for ByteView {
135135
// both strings must have the same prefix and same length
136136
//
137137
// If we are inlined, the other string must be inlined too,
138-
// so checking the prefix is enough
138+
// so checking the short slice is enough
139139
if self.is_inline() {
140140
self.get_short_slice() == other.get_short_slice()
141141
} else {
@@ -263,18 +263,6 @@ impl ByteView {
263263
Ok(s)
264264
}
265265

266-
/// Creates a new zeroed, fixed-length byteview.
267-
///
268-
/// Use [`ByteView::get_mut`] to mutate the content.
269-
///
270-
/// # Panics
271-
///
272-
/// Panics if the length does not fit in a u32 (4 GiB).
273-
#[must_use]
274-
pub fn with_size(slice_len: usize) -> Self {
275-
Self::with_size_zeroed(slice_len)
276-
}
277-
278266
/// Fuses two byte slices into a single byteview.
279267
#[must_use]
280268
pub fn fused(left: &[u8], right: &[u8]) -> Self {
@@ -297,6 +285,18 @@ impl ByteView {
297285
builder
298286
}
299287

288+
/// Creates a new zeroed, fixed-length byteview.
289+
///
290+
/// Use [`ByteView::get_mut`] to mutate the content.
291+
///
292+
/// # Panics
293+
///
294+
/// Panics if the length does not fit in a u32 (4 GiB).
295+
#[must_use]
296+
pub fn with_size(slice_len: usize) -> Self {
297+
Self::with_size_zeroed(slice_len)
298+
}
299+
300300
/// Creates a new zeroed, fixed-length byteview.
301301
///
302302
/// # Panics
@@ -357,12 +357,14 @@ impl ByteView {
357357
view
358358
}
359359

360-
/// Creates a new fixed-length byteview, with uninitialized contents.
360+
/// Creates a new fixed-length byteview, **with uninitialized contents**.
361361
///
362362
/// # Panics
363363
///
364364
/// Panics if the length does not fit in a u32 (4 GiB).
365-
fn with_size_unchecked(slice_len: usize) -> Self {
365+
#[doc(hidden)]
366+
#[must_use]
367+
pub fn with_size_unzeroed(slice_len: usize) -> Self {
366368
let view = if slice_len <= INLINE_SIZE {
367369
Self {
368370
trailer: Trailer {
@@ -652,7 +654,7 @@ impl ByteView {
652654

653655
debug_assert!(
654656
len <= INLINE_SIZE,
655-
"cannot get short slice - slice is not inlined"
657+
"cannot get short slice - slice is not inlined",
656658
);
657659

658660
// SAFETY: Shall only be called if slice is inlined

0 commit comments

Comments
 (0)