mirror of
https://github.com/bspeice/kaitai_rust
synced 2024-11-21 21:38: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)]
|
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||||
pub enum KError<'a> {
|
pub enum KError<'a> {
|
||||||
Incomplete(Needed),
|
Incomplete(Needed),
|
||||||
|
EmptyIterator,
|
||||||
Encoding { expected: &'static str },
|
Encoding { expected: &'static str },
|
||||||
MissingInstanceValue,
|
MissingInstanceValue,
|
||||||
MissingRoot,
|
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
Loading…
Reference in New Issue
Block a user