Skip to content

Commit 9b1e8ac

Browse files
committed
Debug impl
1 parent edd658a commit 9b1e8ac

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

Cargo.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@
22
name = "vec-belt"
33
description = "Multi-threaded bulk-append, single-threaded consume `Vec<T>`."
44
authors = ["GlFolker"]
5-
version = "1.2.0"
5+
version = "1.3.0"
66
edition = "2024"
7-
exclude = [
8-
"benches",
9-
"bench_result",
10-
"tests",
11-
]
7+
exclude = ["benches", "bench_result", "tests"]
128
license = "MIT OR Apache-2.0"
139
repository = "https://github.com/GlennFolker/vec-belt"
1410

@@ -21,7 +17,11 @@ crossbeam-utils = { version = "0.8", default-features = false }
2117
likely_stable = "0.1"
2218

2319
[dev-dependencies]
24-
criterion = { version = "0.5", default-features = false, features = ["cargo_bench_support", "plotters", "html_reports"] }
20+
criterion = { version = "0.5", default-features = false, features = [
21+
"cargo_bench_support",
22+
"plotters",
23+
"html_reports",
24+
] }
2525

2626
[[test]]
2727
name = "vec_belt"
File renamed without changes.

src/lib.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use alloc::{
1212
};
1313
use core::{
1414
cell::UnsafeCell,
15+
fmt,
1516
marker::PhantomData,
1617
mem::{ManuallyDrop, MaybeUninit},
1718
ops::{Deref, DerefMut},
@@ -92,6 +93,14 @@ pub struct VecBelt<T> {
9293
tail: UnsafeCell<NonNull<Fragment<T>>>,
9394
}
9495

96+
impl<T> fmt::Debug for VecBelt<T> {
97+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
98+
f.debug_struct(core::any::type_name::<T>())
99+
.field("len", &self.len())
100+
.finish_non_exhaustive()
101+
}
102+
}
103+
95104
/// # Safety
96105
///
97106
/// [`VecBelt<T>`] provides synchronization primitives that won't lead to data races.
@@ -121,26 +130,26 @@ impl<T> VecBelt<T> {
121130
/// Reads the length of the vector atomically. Prefer [`len_mut`](Self::len_mut) if possible.
122131
#[inline]
123132
pub fn len(&self) -> usize {
124-
self.len.load(Relaxed)
133+
self.len.load(Relaxed) & MASK
125134
}
126135

127136
/// Tests whether the vector is empty atomically. Prefer [`is_empty_mut`](Self::is_empty_mut) if
128137
/// possible.
129138
#[inline]
130139
pub fn is_empty(&self) -> bool {
131-
self.len.load(Relaxed) == 0
140+
self.len.load(Relaxed) & MASK == 0
132141
}
133142

134143
/// Reads the length of the vector non-atomically via `&mut self`.
135144
#[inline]
136145
pub fn len_mut(&mut self) -> usize {
137-
*self.len.get_mut()
146+
*self.len.get_mut() & MASK
138147
}
139148

140149
/// Tests whether the vector is empty non-atomically via `&mut self`.
141150
#[inline]
142151
pub fn is_empty_mut(&mut self) -> bool {
143-
*self.len.get_mut() == 0
152+
*self.len.get_mut() & MASK == 0
144153
}
145154

146155
/// Extends the vector by `additional` elements, returning an uninitialized slice to it and the

0 commit comments

Comments
 (0)