-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from quartiq/rj/getters-generic
rj/getters generic
- Loading branch information
Showing
7 changed files
with
82 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,25 @@ | ||
use num_traits::ops::wrapping::WrappingAdd; | ||
|
||
#[derive(Copy, Clone, Default, PartialEq, Debug)] | ||
pub struct Accu { | ||
state: i32, | ||
step: i32, | ||
pub struct Accu<T> { | ||
state: T, | ||
step: T, | ||
} | ||
|
||
impl Accu { | ||
pub fn new(state: i32, step: i32) -> Self { | ||
impl<T> Accu<T> { | ||
pub fn new(state: T, step: T) -> Self { | ||
Self { state, step } | ||
} | ||
} | ||
|
||
impl Iterator for Accu { | ||
type Item = i32; | ||
fn next(&mut self) -> Option<i32> { | ||
impl<T> Iterator for Accu<T> | ||
where | ||
T: WrappingAdd + Copy, | ||
{ | ||
type Item = T; | ||
fn next(&mut self) -> Option<T> { | ||
let s = self.state; | ||
self.state = self.state.wrapping_add(self.step); | ||
self.state = s.wrapping_add(&self.step); | ||
Some(s) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters