Skip to content

Commit 5ea706b

Browse files
committed
fix handout for extra credit
1 parent a220333 commit 5ea706b

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

week9/splitlab/src/split_pattern.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,39 @@
11
/// A struct that represents split operations on a string.
2-
///
3-
/// TODO(student): You will need to change the `SplitPattern` struct to use lifetime parameter(s).
4-
pub struct SplitPattern<P> {
2+
pub struct SplitPattern<'a, P> {
53
/// The remainder of the string that has not yet been split.
64
///
75
/// Before the iterator has yielded any substrings, this is the entire string.
86
/// After each call to `next`, this is the part of the string that has not yet been split.
9-
///
10-
/// TODO(student): Replace the `'static` lifetime with something else!
11-
remainder: Option<&'static str>,
7+
remainder: Option<&'a str>,
128

139
/// The generic delimiter pattern used to split the haystack string.
1410
delimiter: P,
1511
}
1612

17-
impl<P> SplitPattern<P> {
13+
impl<'a, P> SplitPattern<'a, P> {
1814
/// Creates a new `Split` instance with the given haystack and delimiter.
19-
///
20-
/// TODO(student): Replace the `'static` lifetime with something else!
21-
pub fn new(haystack: &'static str, delimiter: P) -> Self {
15+
pub fn new(haystack: &'a str, delimiter: P) -> Self {
2216
Self {
2317
remainder: Some(haystack),
2418
delimiter,
2519
}
2620
}
2721
}
2822

29-
impl<P> Iterator for SplitPattern<P>
23+
impl<'a, P> Iterator for SplitPattern<'a, P>
3024
where
3125
P: Pattern,
3226
{
3327
/// This iterator yields substrings of the original `haystack` string, split by some delimiter
3428
/// pattern.
35-
///
36-
/// TODO(student): Replace the `'static` lifetime with something else!
37-
type Item = &'static str;
29+
type Item = &'a str;
3830

3931
/// Returns the next substring of the original `haystack` string, split by some delimiter
4032
/// pattern.
4133
///
4234
/// Panics if the delimiter is empty (length 0).
4335
fn next(&mut self) -> Option<Self::Item> {
44-
todo!("Implement me (make sure to fix the lifetimes!)")
36+
todo!("Implement me!")
4537
}
4638
}
4739

0 commit comments

Comments
 (0)