-
Notifications
You must be signed in to change notification settings - Fork 25
Open
Description
The native EdgeDB type looks like this:
pub struct Range<T> {
pub(crate) lower: Option<T>,
pub(crate) upper: Option<T>,
pub(crate) inc_lower: bool,
pub(crate) inc_upper: bool,
pub(crate) empty: bool,
}
I think a more idomatic way of representing that would be one of the following. All of these can still represent every valid edgedb value.
I don't think these are breaking changes, since the current struct has private fields. However the fields have corresponding public accessors, which I'd like to get rid of if breaking changes are allowed (or at least deprecate).
use core::ops::Bound;
pub enum Range<T> {
Empty,
NonEmpty(Bound<T>, Bound<T>),
}
or
use core::ops::Bound;
pub enum Range<T> {
Empty,
NonEmpty { lower: Bound<T>, upper: Bound<T> },
}
or
use core::ops::Bound;
pub struct BoundedRange<T> {
lower_bound: Bound<T>,
upper_bound: Bound<T>,
}
pub enum Range<T> {
Empty,
NonEmpty(BoundedRange<T>),
}
or
pub struct BoundedRange<T>; // as above
pub struct MaybeEmptyRange<R>(inner:Option<R>);
type Range<T> = MaybeEmptyRange<BoundedRange<T>>;
I like the last one best, since it NonEmptyRange
could be useful to be used in the model if the user knows it's never empty. It could also come in handy to model multi-ranges as something like Vec<NonEmptyRange<T>>
(I'm assuming multi-ranges can't contain individual empty ranges).
Metadata
Metadata
Assignees
Labels
No labels