diff --git a/src/lib.rs b/src/lib.rs index 46aa805..d083f0b 100644 --- a/src/lib.rs +++ b/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::*;