mirror of
https://github.com/kmc7468/cs220.git
synced 2025-12-12 21:08:45 +00:00
30 lines
788 B
Rust
30 lines
788 B
Rust
//! Assignment 7: Mastering advanced types (2/2).
|
|
//!
|
|
//! The primary goal of this assignment is to understand generics, traits, and lifetimes.
|
|
//!
|
|
//! You should fill out the `todo!()` placeholders in such a way that `/scripts/grade-07.sh` works fine.
|
|
//! See `assignment07_grade.rs` and `/scripts/grade-07.sh` for the test script.
|
|
|
|
struct FindIter<'s, T: Eq> {
|
|
query: &'s [T],
|
|
base: &'s [T],
|
|
curr: usize,
|
|
}
|
|
|
|
impl<T: Eq> Iterator for FindIter<'_, T> {
|
|
type Item = usize;
|
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
todo!()
|
|
}
|
|
}
|
|
|
|
/// Returns an iterator over substring query indexes in the base.
|
|
pub fn find<'s, T: Eq>(query: &'s [T], base: &'s [T]) -> impl 's + Iterator<Item = usize> {
|
|
FindIter {
|
|
query,
|
|
base,
|
|
curr: 0,
|
|
}
|
|
}
|