Document that index and index_mut can panic

This commit is contained in:
r00ster 2021-04-18 15:51:16 +02:00 committed by GitHub
parent d7c3386414
commit df01b3a67b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -61,6 +61,10 @@ pub trait Index<Idx: ?Sized> {
type Output: ?Sized;
/// Performs the indexing (`container[index]`) operation.
///
/// # Panics
///
/// Panics if the index is out of bounds.
#[stable(feature = "rust1", since = "1.0.0")]
#[track_caller]
fn index(&self, index: Idx) -> &Self::Output;
@ -161,6 +165,10 @@ see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#ind
#[doc(alias = "[]")]
pub trait IndexMut<Idx: ?Sized>: Index<Idx> {
/// Performs the mutable indexing (`container[index]`) operation.
///
/// # Panics
///
/// Panics if the index is out of bounds.
#[stable(feature = "rust1", since = "1.0.0")]
#[track_caller]
fn index_mut(&mut self, index: Idx) -> &mut Self::Output;