Restructure range! internals a bit

This commit is contained in:
Steven Fackler 2014-07-26 00:12:25 -07:00
parent bb6fbfbc6f
commit dfde45e7c7

View File

@ -9,11 +9,6 @@ use time::Timespec;
/// The `quote!` macro can make it easier to create ranges. It roughly mirrors
/// traditional mathematic range syntax.
///
/// # Note
///
/// The `Range`, `RangeBound`, `Inclusive`, and `Exclusive` types must be
/// directly usable at the location the macro is used.
///
/// # Example
///
/// ```rust
@ -22,10 +17,10 @@ use time::Timespec;
/// #[phase(syntax, link)]
/// extern crate postgres;
///
/// use postgres::types::range::{Range, RangeBound, Inclusive, Exclusive};
/// use postgres::types::range::Range;
///
/// fn main() {
/// # let mut r: Range<i32>;
/// let mut r: Range<i32>;
/// // a closed interval
/// r = range!('[' 5i32, 10i32 ']');
/// // an open interval
@ -48,35 +43,55 @@ use time::Timespec;
/// }
#[macro_export]
macro_rules! range(
(empty) => (Range::empty());
('(', ')') => (Range::new(None, None));
(empty) => (::postgres::types::range::Range::empty());
('(', ')') => (::postgres::types::range::Range::new(None, None));
('(', $h:expr ')') => (
Range::new(None, Some(RangeBound::new($h, Exclusive)))
::postgres::types::range::Range::new(None,
Some(::postgres::types::range::RangeBound::new($h,
::postgres::types::range::Exclusive)))
);
('(', $h:expr ']') => (
Range::new(None, Some(RangeBound::new($h, Inclusive)))
::postgres::types::range::Range::new(None,
Some(::postgres::types::range::RangeBound::new($h,
::postgres::types::range::Inclusive)))
);
('(' $l:expr, ')') => (
Range::new(Some(RangeBound::new($l, Exclusive)), None)
::postgres::types::range::Range::new(
Some(::postgres::types::range::RangeBound::new($l,
::postgres::types::range::Exclusive)), None)
);
('[' $l:expr, ')') => (
Range::new(Some(RangeBound::new($l, Inclusive)), None)
::postgres::types::range::Range::new(
Some(::postgres::types::range::RangeBound::new($l,
::postgres::types::range::Inclusive)), None)
);
('(' $l:expr, $h:expr ')') => (
Range::new(Some(RangeBound::new($l, Exclusive)),
Some(RangeBound::new($h, Exclusive)))
::postgres::types::range::Range::new(
Some(::postgres::types::range::RangeBound::new($l,
::postgres::types::range::Exclusive)),
Some(::postgres::types::range::RangeBound::new($h,
::postgres::types::range::Exclusive)))
);
('(' $l:expr, $h:expr ']') => (
Range::new(Some(RangeBound::new($l, Exclusive)),
Some(RangeBound::new($h, Inclusive)))
::postgres::types::range::Range::new(
Some(::postgres::types::range::RangeBound::new($l,
::postgres::types::range::Exclusive)),
Some(::postgres::types::range::RangeBound::new($h,
::postgres::types::range::Inclusive)))
);
('[' $l:expr, $h:expr ')') => (
Range::new(Some(RangeBound::new($l, Inclusive)),
Some(RangeBound::new($h, Exclusive)))
::postgres::types::range::Range::new(
Some(::postgres::types::range::RangeBound::new($l,
::postgres::types::range::Inclusive)),
Some(::postgres::types::range::RangeBound::new($h,
::postgres::types::range::Exclusive)))
);
('[' $l:expr, $h:expr ']') => (
Range::new(Some(RangeBound::new($l, Inclusive)),
Some(RangeBound::new($h, Inclusive)))
::postgres::types::range::Range::new(
Some(::postgres::types::range::RangeBound::new($l,
::postgres::types::range::Inclusive)),
Some(::postgres::types::range::RangeBound::new($h,
::postgres::types::range::Inclusive)))
)
)