Skip to content

Commit dde6f94

Browse files
committed
DOC: Improve docs for .index() and friends
- Point out all panic cases - Link to the more common methods
1 parent b2abf1c commit dde6f94

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

src/impl_views.rs

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,15 @@ impl<'a, A, D> ArrayView<'a, A, D>
137137
/// Get a reference of a element through the view.
138138
///
139139
/// This method is like `Index::index` but with a longer lifetime (matching
140-
/// the array view); which we can't do for general arrays and not in the
140+
/// the array view); which we can only do for the array view and not in the
141141
/// `Index` trait.
142+
///
143+
/// See also [the `get` method][1] which works for all arrays and array
144+
/// views.
145+
///
146+
/// [1]: struct.ArrayBase.html#method.get
147+
///
148+
/// **Panics** if index is out of bounds.
142149
pub fn index<I>(&self, index: I) -> &'a A
143150
where I: NdIndex<D>,
144151
{
@@ -154,6 +161,13 @@ impl<'a, A, D> ArrayView<'a, A, D>
154161
///
155162
/// This method is like `elem` with a longer lifetime (matching the array
156163
/// view); which we can't do for general arrays.
164+
///
165+
/// See also [the `uget` method][1] which works for all arrays and array
166+
/// views.
167+
///
168+
/// [1]: struct.ArrayBase.html#method.uget
169+
///
170+
/// **Note:** only unchecked for non-debug builds of ndarray.
157171
pub unsafe fn uindex<I>(&self, index: I) -> &'a A
158172
where I: NdIndex<D>,
159173
{
@@ -263,9 +277,16 @@ impl<'a, A, D> ArrayViewMut<'a, A, D>
263277

264278
/// Convert a mutable array view to a mutable reference of a element.
265279
///
266-
/// This method is like `Index::index` but with a longer lifetime (matching
267-
/// the array view); which we can't do for general arrays and not in the
268-
/// `Index` trait.
280+
/// This method is like `IndexMut::index_mut` but with a longer lifetime
281+
/// (matching the array view); which we can only do for the array view and
282+
/// not in the `Index` trait.
283+
///
284+
/// See also [the `get_mut` method][1] which works for all arrays and array
285+
/// views.
286+
///
287+
/// [1]: struct.ArrayBase.html#method.get_mut
288+
///
289+
/// **Panics** if index is out of bounds.
269290
pub fn into_index_mut<I>(mut self, index: I) -> &'a mut A
270291
where I: NdIndex<D>,
271292
{
@@ -279,9 +300,15 @@ impl<'a, A, D> ArrayViewMut<'a, A, D>
279300
}
280301
}
281302

282-
/// Convert a mutable array view to a mutable reference of a element without boundary check
303+
/// Convert a mutable array view to a mutable reference of a element without
304+
/// boundary check.
305+
///
306+
/// See also [the `uget_mut` method][1] which works for all arrays and array
307+
/// views.
283308
///
309+
/// [1]: struct.ArrayBase.html#method.uget_mut
284310
///
311+
/// **Note:** only unchecked for non-debug builds of ndarray.
285312
pub unsafe fn into_index_mut_unchecked<I>(mut self, index: I) -> &'a mut A
286313
where I: NdIndex<D>
287314
{

0 commit comments

Comments
 (0)