Skip to content

Commit 934ae4d

Browse files
committed
Make value-internal IValue accessors private
Now that the representations are submodules of `value`, they can see `value`'s private items directly, so the low-level `IValue` accessors they use no longer need `pub(crate)`. Make `ALIGNMENT`, `TypeTag`, `new_inline`, `new_ptr`, `new_ref`, `ptr_usize`, `ptr`, `set_ptr`, `set_ref`, `raw_copy` and `type_tag` private to the `value` module. Only `raw_eq`, `raw_hash` (used by the `IString` facade) and `is_inline` (used by the `INumber`/`IString` facade tests) remain `pub(crate)`.
1 parent e093455 commit 934ae4d

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

src/value/mod.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl Deref for BoolMut<'_> {
180180
}
181181
}
182182

183-
pub(crate) const ALIGNMENT: usize = 8;
183+
const ALIGNMENT: usize = 8;
184184

185185
// All heap allocations pointed to by an `IValue` are aligned to `ALIGNMENT`, so
186186
// the low 3 bits of the pointer are free to hold the `TypeTag`. Every non-inline
@@ -190,7 +190,7 @@ pub(crate) const ALIGNMENT: usize = 8;
190190

191191
#[repr(usize)]
192192
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
193-
pub(crate) enum TypeTag {
193+
enum TypeTag {
194194
/// A value stored entirely inline (null, bool, small number, short string).
195195
Inline = 0,
196196
/// Pointer to a heap `i64` payload.
@@ -245,19 +245,19 @@ impl IValue {
245245
// corrupt the tag when ORed in) and, together with the tag, must not be
246246
// all-zero (reserved as the niche). Used to build inline values; `tag` is
247247
// normally `Inline`, with the payload carrying the sub-family and data.
248-
pub(crate) const unsafe fn new_inline(tag: TypeTag, payload: usize) -> Self {
248+
const unsafe fn new_inline(tag: TypeTag, payload: usize) -> Self {
249249
Self {
250250
ptr: NonNull::new_unchecked((tag as usize | payload) as *mut u8),
251251
}
252252
}
253253
// Safety: Pointer must be non-null and aligned to at least ALIGNMENT
254-
pub(crate) unsafe fn new_ptr(p: NonNull<u8>, tag: TypeTag) -> Self {
254+
unsafe fn new_ptr(p: NonNull<u8>, tag: TypeTag) -> Self {
255255
Self {
256256
ptr: p.add(tag as usize),
257257
}
258258
}
259259
// Safety: Reference must be aligned to at least ALIGNMENT
260-
pub(crate) unsafe fn new_ref<T>(r: &T, tag: TypeTag) -> Self {
260+
unsafe fn new_ref<T>(r: &T, tag: TypeTag) -> Self {
261261
Self::new_ptr(NonNull::from_ref(r).cast(), tag)
262262
}
263263

@@ -268,23 +268,23 @@ impl IValue {
268268
/// JSON `true`.
269269
pub const TRUE: Self = unsafe { Self::new_inline(TypeTag::Inline, inline::TRUE) };
270270

271-
pub(crate) fn ptr_usize(&self) -> usize {
271+
fn ptr_usize(&self) -> usize {
272272
self.ptr.as_ptr() as usize
273273
}
274274
// Safety: Must only be called on non-inline types
275-
pub(crate) unsafe fn ptr(&self) -> NonNull<u8> {
275+
unsafe fn ptr(&self) -> NonNull<u8> {
276276
self.ptr.offset(-((self.ptr_usize() % ALIGNMENT) as isize))
277277
}
278278
// Safety: Pointer must be non-null and aligned to at least ALIGNMENT
279-
pub(crate) unsafe fn set_ptr(&mut self, ptr: NonNull<u8>) {
279+
unsafe fn set_ptr(&mut self, ptr: NonNull<u8>) {
280280
let tag = self.type_tag();
281281
self.ptr = ptr.add(tag as usize);
282282
}
283283
// Safety: Reference must be aligned to at least ALIGNMENT
284-
pub(crate) unsafe fn set_ref<T>(&mut self, r: &T) {
284+
unsafe fn set_ref<T>(&mut self, r: &T) {
285285
self.set_ptr(NonNull::from_ref(r).cast());
286286
}
287-
pub(crate) unsafe fn raw_copy(&self) -> Self {
287+
unsafe fn raw_copy(&self) -> Self {
288288
Self { ptr: self.ptr }
289289
}
290290
pub(crate) fn raw_eq(&self, other: &Self) -> bool {
@@ -293,7 +293,7 @@ impl IValue {
293293
pub(crate) fn raw_hash<H: std::hash::Hasher>(&self, state: &mut H) {
294294
self.ptr.hash(state);
295295
}
296-
pub(crate) fn type_tag(&self) -> TypeTag {
296+
fn type_tag(&self) -> TypeTag {
297297
self.ptr_usize().into()
298298
}
299299

0 commit comments

Comments
 (0)