mirror of
https://github.com/bspeice/kaitai_rust
synced 2024-11-21 05:18:09 -05:00
Add some methods for helping with iterators
This commit is contained in:
parent
1c15eb14d6
commit
d41f578c83
25
src/lib.rs
25
src/lib.rs
@ -9,6 +9,7 @@ pub enum Needed {
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
pub enum KError<'a> {
|
||||
Incomplete(Needed),
|
||||
EmptyIterator,
|
||||
Encoding { expected: &'static str },
|
||||
MissingInstanceValue,
|
||||
MissingRoot,
|
||||
@ -274,6 +275,30 @@ impl<'a> KStream for BytesReader<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! kf_max {
|
||||
($i: ident, $t: ty) => (
|
||||
pub fn $i<'a>(first: Option<&'a $t>, second: &'a $t) -> Option<&'a $t> {
|
||||
if second.is_nan() { first }
|
||||
else if first.is_none() { Some(second) }
|
||||
else { if first.unwrap() < second { Some(second) } else { first } }
|
||||
}
|
||||
)
|
||||
}
|
||||
kf_max!(kf32_max, f32);
|
||||
kf_max!(kf64_max, f64);
|
||||
|
||||
macro_rules! kf_min {
|
||||
($i: ident, $t: ty) => (
|
||||
pub fn $i<'a>(first: Option<&'a $t>, second: &'a $t) -> Option<&'a $t> {
|
||||
if second.is_nan() { first }
|
||||
else if first.is_none() { Some(second) }
|
||||
else { if first.unwrap() < second { first } else { Some(second) } }
|
||||
}
|
||||
)
|
||||
}
|
||||
kf_min!(kf32_min, f32);
|
||||
kf_min!(kf64_min, f64);
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
Loading…
Reference in New Issue
Block a user