Skip to content

Commit 21485b4

Browse files
jldBurntSushi
authored andcommitted
Add documentation for the lifetimes for Captures as Index.
1 parent b4556a1 commit 21485b4

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
@@ -976,6 +976,15 @@ impl<'t> Captures<'t> {
976976

977977
/// Get a group by index.
978978
///
979+
/// `'t` is the lifetime of the matched text.
980+
///
981+
/// The text can't outlive the `Captures` object if this method is
982+
/// used, because of how `Index` is defined (normally `a[i]` is part
983+
/// of `a` and can't outlive it); to do that, use [`at()`][]
984+
/// instead.
985+
///
986+
/// [`at()`]: #method.at
987+
///
979988
/// # Panics
980989
/// If there is no group at the given index.
981990
impl<'t> Index<usize> for Captures<'t> {
@@ -990,6 +999,16 @@ impl<'t> Index<usize> for Captures<'t> {
990999

9911000
/// Get a group by name.
9921001
///
1002+
/// `'t` is the lifetime of the matched text and `'i` is the lifetime
1003+
/// of the group name (the index).
1004+
///
1005+
/// The text can't outlive the `Captures` object if this method is
1006+
/// used, because of how `Index` is defined (normally `a[i]` is part
1007+
/// of `a` and can't outlive it); to do that, use [`name()`][]
1008+
/// instead.
1009+
///
1010+
/// [`name()`]: #method.name
1011+
///
9931012
/// # Panics
9941013
/// If there is no group named by the given value.
9951014
impl<'t, 'i> Index<&'i str> for Captures<'t> {

0 commit comments

Comments
 (0)