Update for numeric trait changes

This commit is contained in:
Steven Fackler 2014-01-16 22:29:58 -08:00
parent 203a5e5784
commit 5b364ab759
2 changed files with 15 additions and 10 deletions

View File

@ -229,10 +229,11 @@ impl<W: Writer> WriteMessage for W {
None => ()
}
let buf = buf.unwrap();
// add size of length value
self.write_be_i32((buf.get_ref().len() + mem::size_of::<i32>())
as i32);
self.write(buf.unwrap());
self.write_be_i32((buf.len() + mem::size_of::<i32>()) as i32);
self.write(buf);
}
}

View File

@ -4,6 +4,8 @@
extern mod extra;
use std::cmp;
use std::i32;
use std::i64;
use extra::time::Timespec;
macro_rules! range(
@ -54,17 +56,17 @@ pub trait Normalizable {
}
macro_rules! bounded_normalizable(
($t:ty) => (
($t:ident) => (
impl Normalizable for $t {
fn normalize<S: BoundSided>(bound: RangeBound<S, $t>)
-> RangeBound<S, $t> {
match (BoundSided::side(None::<S>), bound.type_) {
(Upper, Inclusive) => {
assert!(bound.value != Bounded::max_value());
assert!(bound.value != $t::max_value);
RangeBound::new(bound.value + 1, Exclusive)
}
(Lower, Exclusive) => {
assert!(bound.value != Bounded::max_value());
assert!(bound.value != $t::max_value);
RangeBound::new(bound.value + 1, Inclusive)
}
_ => bound
@ -281,6 +283,8 @@ impl<T: Ord+Normalizable+Clone> Range<T> {
#[cfg(test)]
mod test {
use std::i32;
use super::*;
#[test]
@ -364,17 +368,17 @@ mod test {
let r = range!('(', 3i32 ']');
assert!(!r.contains(&4));
assert!(r.contains(&2));
assert!(r.contains(&Bounded::min_value()));
assert!(r.contains(&i32::min_value));
let r = range!('[' 1i32, ')');
assert!(r.contains(&Bounded::max_value()));
assert!(r.contains(&i32::max_value));
assert!(r.contains(&4));
assert!(!r.contains(&0));
let r = range!('(', ')');
assert!(r.contains(&Bounded::max_value()));
assert!(r.contains(&i32::max_value));
assert!(r.contains(&0i32));
assert!(r.contains(&Bounded::min_value()));
assert!(r.contains(&i32::min_value));
}
#[test]