mirror of
https://github.com/kmc7468/cs220.git
synced 2025-12-14 22:18:46 +00:00
Add assignment 7
This commit is contained in:
29
src/assignments/assignment07.rs
Normal file
29
src/assignments/assignment07.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
//! 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,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user