Skip to content

Commit 5a0f868

Browse files
committed
docs: Remove #[doc(hidden)] and add documentation for internal traits
1 parent 49cbd5d commit 5a0f868

6 files changed

Lines changed: 32 additions & 53 deletions

File tree

src/data_traits.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ pub unsafe trait RawData: Sized
3939
{
4040
/// The array element type.
4141
type Elem;
42-
43-
#[doc(hidden)]
42+
/// Returns whether `self_ptr` points within this data's memory bounds.
43+
///
44+
/// Valid range includes all element positions plus one-past-the-end.
45+
/// Used for internal bounds checking in unsafe operations.
4446
fn _is_pointer_inbounds(&self, ptr: *const Self::Elem) -> bool;
4547

4648
private_decl! {}
@@ -61,7 +63,6 @@ pub unsafe trait RawDataMut: RawData
6163
///
6264
/// Additionally, if `Self` provides safe mutable access to array elements,
6365
/// then this method **must** panic or ensure that the data is unique.
64-
#[doc(hidden)]
6566
fn try_ensure_unique<D>(_: &mut ArrayBase<Self, D>)
6667
where
6768
Self: Sized,
@@ -71,7 +72,6 @@ pub unsafe trait RawDataMut: RawData
7172
///
7273
/// If `Self` provides safe mutable access to array elements, then it
7374
/// **must** return `Some(_)`.
74-
#[doc(hidden)]
7575
fn try_is_unique(&mut self) -> Option<bool>;
7676
}
7777

@@ -83,11 +83,10 @@ pub unsafe trait RawDataMut: RawData
8383
#[allow(clippy::missing_safety_doc)] // not implementable downstream
8484
pub unsafe trait RawDataClone: RawData
8585
{
86-
#[doc(hidden)]
8786
/// Unsafe because, `ptr` must point inside the current storage.
8887
unsafe fn clone_with_ptr(&self, ptr: NonNull<Self::Elem>) -> (Self, NonNull<Self::Elem>);
89-
90-
#[doc(hidden)]
88+
/// Clones data from `other` into `self`, adjusting the pointer accordingly. `ptr` must point
89+
/// inside `other`'s storage.
9190
unsafe fn clone_from_with_ptr(&mut self, other: &Self, ptr: NonNull<Self::Elem>) -> NonNull<Self::Elem>
9291
{
9392
let (data, ptr) = other.clone_with_ptr(ptr);
@@ -105,7 +104,6 @@ pub unsafe trait RawDataClone: RawData
105104
pub unsafe trait Data: RawData
106105
{
107106
/// Converts the array to a uniquely owned array, cloning elements if necessary.
108-
#[doc(hidden)]
109107
#[allow(clippy::wrong_self_convention)]
110108
fn into_owned<D>(self_: ArrayBase<Self, D>) -> Array<Self::Elem, D>
111109
where
@@ -114,13 +112,11 @@ pub unsafe trait Data: RawData
114112

115113
/// Converts the array into `Array<A, D>` if this is possible without
116114
/// cloning the array elements. Otherwise, returns `self_` unchanged.
117-
#[doc(hidden)]
118115
fn try_into_owned_nocopy<D>(self_: ArrayBase<Self, D>) -> Result<Array<Self::Elem, D>, ArrayBase<Self, D>>
119116
where D: Dimension;
120117

121118
/// Return a shared ownership (copy on write) array based on the existing one,
122119
/// cloning elements if necessary.
123-
#[doc(hidden)]
124120
#[allow(clippy::wrong_self_convention)]
125121
fn to_shared<D>(self_: &ArrayBase<Self, D>) -> ArcArray<Self::Elem, D>
126122
where
@@ -148,7 +144,6 @@ pub unsafe trait Data: RawData
148144
pub unsafe trait DataMut: Data + RawDataMut
149145
{
150146
/// Ensures that the array has unique access to its data.
151-
#[doc(hidden)]
152147
#[inline]
153148
fn ensure_unique<D>(self_: &mut ArrayBase<Self, D>)
154149
where
@@ -159,7 +154,6 @@ pub unsafe trait DataMut: Data + RawDataMut
159154
}
160155

161156
/// Returns whether the array has unique access to its data.
162-
#[doc(hidden)]
163157
#[inline]
164158
#[allow(clippy::wrong_self_convention)] // mut needed for Arc types
165159
fn is_unique(&mut self) -> bool
@@ -514,12 +508,11 @@ pub unsafe trait DataOwned: Data
514508
{
515509
/// Corresponding owned data with MaybeUninit elements
516510
type MaybeUninit: DataOwned<Elem = MaybeUninit<Self::Elem>> + RawDataSubst<Self::Elem, Output = Self>;
517-
#[doc(hidden)]
511+
/// Creates an owned representation from the given elements.
518512
fn new(elements: Vec<Self::Elem>) -> Self;
519513

520514
/// Converts the data representation to a shared (copy on write)
521515
/// representation, cloning the array elements if necessary.
522-
#[doc(hidden)]
523516
#[allow(clippy::wrong_self_convention)]
524517
fn into_shared<D>(self_: ArrayBase<Self, D>) -> ArcArray<Self::Elem, D>
525518
where

src/dimension/dimension_trait.rs

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ pub trait Dimension:
9696
.try_fold(1_usize, |s, &a| s.checked_mul(a))
9797
}
9898

99-
#[doc(hidden)]
99+
/// Returns the dimension as a slice of axis lengths.
100100
fn slice(&self) -> &[Ix];
101-
102-
#[doc(hidden)]
101+
102+
/// Returns the dimension as a mutable slice of axis lengths.
103103
fn slice_mut(&mut self) -> &mut [Ix];
104104

105105
/// Borrow as a read-only array view.
@@ -114,7 +114,7 @@ pub trait Dimension:
114114
ArrayViewMut1::from(self.slice_mut())
115115
}
116116

117-
#[doc(hidden)]
117+
/// Returns `true` if the dimensions have equal axis lengths.
118118
fn equal(&self, rhs: &Self) -> bool
119119
{
120120
self.slice() == rhs.slice()
@@ -124,7 +124,6 @@ pub trait Dimension:
124124
///
125125
/// If the array is non-empty, the strides result in contiguous layout; if
126126
/// the array is empty, the strides are all zeros.
127-
#[doc(hidden)]
128127
fn default_strides(&self) -> Self
129128
{
130129
// Compute default array strides
@@ -150,7 +149,6 @@ pub trait Dimension:
150149
///
151150
/// If the array is non-empty, the strides result in contiguous layout; if
152151
/// the array is empty, the strides are all zeros.
153-
#[doc(hidden)]
154152
fn fortran_strides(&self) -> Self
155153
{
156154
// Compute fortran array strides
@@ -180,7 +178,7 @@ pub trait Dimension:
180178
/// **Panics** if `Self` has a fixed size that is not `ndim`.
181179
fn zeros(ndim: usize) -> Self;
182180

183-
#[doc(hidden)]
181+
/// Returns the first valid index in the dimension, or `None` if any axis has length 0.
184182
#[inline]
185183
fn first_index(&self) -> Option<Self>
186184
{
@@ -192,7 +190,6 @@ pub trait Dimension:
192190
Some(Self::zeros(self.ndim()))
193191
}
194192

195-
#[doc(hidden)]
196193
/// Iteration -- Use self as size, and return next index after `index`
197194
/// or None if there are no more.
198195
// FIXME: use &Self for index or even &mut?
@@ -217,7 +214,6 @@ pub trait Dimension:
217214
}
218215
}
219216

220-
#[doc(hidden)]
221217
/// Iteration -- Use self as size, and create the next index after `index`
222218
/// Return false if iteration is done
223219
///
@@ -245,7 +241,6 @@ pub trait Dimension:
245241
/// strides are equal.
246242
///
247243
/// Note: Returns `false` if any of the ndims don't match.
248-
#[doc(hidden)]
249244
fn strides_equivalent<D>(&self, strides1: &Self, strides2: &D) -> bool
250245
where D: Dimension
251246
{
@@ -256,7 +251,6 @@ pub trait Dimension:
256251
.all(|(&d, &s1, &s2)| d <= 1 || s1 as isize == s2 as isize)
257252
}
258253

259-
#[doc(hidden)]
260254
/// Return stride offset for index.
261255
fn stride_offset(index: &Self, strides: &Self) -> isize
262256
{
@@ -267,14 +261,13 @@ pub trait Dimension:
267261
offset
268262
}
269263

270-
#[doc(hidden)]
271264
/// Return stride offset for this dimension and index.
272265
fn stride_offset_checked(&self, strides: &Self, index: &Self) -> Option<isize>
273266
{
274267
stride_offset_checked(self.slice(), strides.slice(), index.slice())
275268
}
276269

277-
#[doc(hidden)]
270+
/// Returns the size of the last dimension axis, or 0 for scalar (zero-dimensional) arrays.
278271
fn last_elem(&self) -> usize
279272
{
280273
if self.ndim() == 0 {
@@ -283,15 +276,16 @@ pub trait Dimension:
283276
self.slice()[self.ndim() - 1]
284277
}
285278
}
286-
287-
#[doc(hidden)]
279+
/// Sets the length of the last axis to `i`.
288280
fn set_last_elem(&mut self, i: usize)
289281
{
290282
let nd = self.ndim();
291283
self.slice_mut()[nd - 1] = i;
292284
}
293285

294-
#[doc(hidden)]
286+
/// Returns `true` if the dimension and strides represent contiguous memory layout.
287+
///
288+
/// Handles both standard (C-order) and reversed (negative stride) contiguous layouts.
295289
fn is_contiguous(dim: &Self, strides: &Self) -> bool
296290
{
297291
let defaults = dim.default_strides();
@@ -324,7 +318,6 @@ pub trait Dimension:
324318
/// (in ascending order).
325319
///
326320
/// Assumes that no stride value appears twice.
327-
#[doc(hidden)]
328321
fn _fastest_varying_stride_order(&self) -> Self
329322
{
330323
let mut indices = self.clone();
@@ -340,7 +333,6 @@ pub trait Dimension:
340333

341334
/// Compute the minimum stride axis (absolute value), under the constraint
342335
/// that the length of the axis is > 1;
343-
#[doc(hidden)]
344336
fn min_stride_axis(&self, strides: &Self) -> Axis
345337
{
346338
let n = match self.ndim() {
@@ -356,7 +348,6 @@ pub trait Dimension:
356348

357349
/// Compute the maximum stride axis (absolute value), under the constraint
358350
/// that the length of the axis is > 1;
359-
#[doc(hidden)]
360351
fn max_stride_axis(&self, strides: &Self) -> Axis
361352
{
362353
match self.ndim() {
@@ -376,7 +367,7 @@ pub trait Dimension:
376367
IxDyn(self.slice())
377368
}
378369

379-
#[doc(hidden)]
370+
/// Converts from another dimension type, returning `None` if `ndim` differs.
380371
fn from_dimension<D2: Dimension>(d: &D2) -> Option<Self>
381372
{
382373
let mut s = Self::default();
@@ -389,11 +380,11 @@ pub trait Dimension:
389380
None
390381
}
391382
}
392-
393-
#[doc(hidden)]
383+
384+
/// Inserts a new axis of length 1 at the given position, increasing dimensionality.
394385
fn insert_axis(&self, axis: Axis) -> Self::Larger;
395386

396-
#[doc(hidden)]
387+
/// Removes the specified axis, decreasing dimensionality. Panics if axis is invalid.
397388
fn try_remove_axis(&self, axis: Axis) -> Self::Smaller;
398389

399390
private_decl! {}

src/dimension/ndindex.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ use crate::{Dim, Dimension, IntoDimension, Ix, Ix0, Ix1, Ix2, Ix3, Ix4, Ix5, Ix6
1919
#[allow(clippy::missing_safety_doc)] // TODO: Add doc
2020
pub unsafe trait NdIndex<E>: Debug
2121
{
22-
#[doc(hidden)]
22+
/// Computes the linear index for this position
2323
fn index_checked(&self, dim: &E, strides: &E) -> Option<isize>;
24-
#[doc(hidden)]
24+
25+
/// Computes the linear index for this position without bounds checking.
2526
fn index_unchecked(&self, strides: &E) -> isize;
2627
}
2728

src/layout/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ mod layoutfmt;
33
// Layout is a bitset used for internal layout description of
44
// arrays, producers and sets of producers.
55
// The type is public but users don't interact with it.
6-
#[doc(hidden)]
76
/// Memory layout description
87
#[derive(Copy, Clone)]
98
pub struct Layout(u32);

src/slice.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,6 @@ where
484484
/// The caller must ensure that `in_dim` and `out_dim` are consistent with
485485
/// `indices` and that `indices.as_ref()` always returns the same value
486486
/// when called multiple times.
487-
#[doc(hidden)]
488487
pub unsafe fn new_unchecked(
489488
indices: T, in_dim: PhantomData<Din>, out_dim: PhantomData<Dout>,
490489
) -> SliceInfo<T, Din, Dout>
@@ -671,7 +670,6 @@ where
671670
}
672671

673672
/// Trait for determining dimensionality of input and output for [`s!`] macro.
674-
#[doc(hidden)]
675673
pub trait SliceNextDim
676674
{
677675
/// Number of dimensions that this slicing argument consumes in the input array.

src/zip/ndproducer.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,33 +66,30 @@ pub trait NdProducer
6666
// current element. It doesn't have to be a pointer (see Indices).
6767
// Its main function is that it can be incremented with a particular
6868
// stride (= along a particular axis)
69-
#[doc(hidden)]
7069
/// Pointer or stand-in for pointer
7170
type Ptr: Offset<Stride = Self::Stride>;
72-
#[doc(hidden)]
7371
/// Pointer stride
7472
type Stride: Copy;
75-
76-
#[doc(hidden)]
73+
/// Returns the memory layout of this data representation.
7774
fn layout(&self) -> Layout;
7875
/// Return the shape of the producer.
7976
fn raw_dim(&self) -> Self::Dim;
80-
#[doc(hidden)]
77+
/// Returns `true` if this producer's dimension matches the given dimension.
8178
fn equal_dim(&self, dim: &Self::Dim) -> bool
8279
{
8380
self.raw_dim() == *dim
8481
}
85-
#[doc(hidden)]
82+
/// Returns a pointer to the first element of the data.
8683
fn as_ptr(&self) -> Self::Ptr;
87-
#[doc(hidden)]
84+
/// Dereferences the pointer to get a reference to the element.
8885
unsafe fn as_ref(&self, ptr: Self::Ptr) -> Self::Item;
89-
#[doc(hidden)]
86+
/// Returns a pointer to the element at the given index without bounds checking.
9087
unsafe fn uget_ptr(&self, i: &Self::Dim) -> Self::Ptr;
91-
#[doc(hidden)]
88+
/// Returns the stride (offset between elements) along the specified axis.
9289
fn stride_of(&self, axis: Axis) -> <Self::Ptr as Offset>::Stride;
93-
#[doc(hidden)]
90+
/// Returns the stride of the fastest-varying (most contiguous) dimension.
9491
fn contiguous_stride(&self) -> Self::Stride;
95-
#[doc(hidden)]
92+
/// Splits each component of this producer tuple along the specified axis at the given index.
9693
fn split_at(self, axis: Axis, index: usize) -> (Self, Self)
9794
where Self: Sized;
9895

0 commit comments

Comments
 (0)