Skip to content

Commit 18ac6c1

Browse files
committed
Add documentation for the lifetimes for Captures as Index.
1 parent 2fefddd commit 18ac6c1

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/re.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,15 @@ impl<'t> Captures<'t> {
951951

952952
/// Get a group by index.
953953
///
954+
/// `'t` is the lifetime of the matched text.
955+
///
956+
/// The text can't outlive the `Captures` object if this method is
957+
/// used, because of how `Index` is defined (normally `a[i]` is part
958+
/// of `a` and can't outlive it); to do that, use [`at()`][]
959+
/// instead.
960+
///
961+
/// [`at()`]: #method.at
962+
///
954963
/// # Panics
955964
/// If there is no group at the given index.
956965
impl<'t> Index<usize> for Captures<'t> {
@@ -965,6 +974,16 @@ impl<'t> Index<usize> for Captures<'t> {
965974

966975
/// Get a group by name.
967976
///
977+
/// `'t` is the lifetime of the matched text and `'i` is the lifetime
978+
/// of the group name (the index).
979+
///
980+
/// The text can't outlive the `Captures` object if this method is
981+
/// used, because of how `Index` is defined (normally `a[i]` is part
982+
/// of `a` and can't outlive it); to do that, use [`name()`][]
983+
/// instead.
984+
///
985+
/// [`name()`]: #method.name
986+
///
968987
/// # Panics
969988
/// If there is no group named by the given value.
970989
impl<'t, 'i> Index<&'i str> for Captures<'t> {

0 commit comments

Comments
 (0)