#[derive(Debug, Clone)]
pub enum SortOrderPushdownResult<T> {
Exact {
inner: T,
},
Inexact {
inner: T,
},
Unsupported,
}
impl<T> SortOrderPushdownResult<T> {
pub fn into_inner(self) -> Option<T> {
match self {
Self::Exact { inner } | Self::Inexact { inner } => Some(inner),
Self::Unsupported => None,
}
}
pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> SortOrderPushdownResult<U> {
match self {
Self::Exact { inner } => SortOrderPushdownResult::Exact { inner: f(inner) },
Self::Inexact { inner } => {
SortOrderPushdownResult::Inexact { inner: f(inner) }
}
Self::Unsupported => SortOrderPushdownResult::Unsupported,
}
}
pub fn try_map<U, E, F: FnOnce(T) -> Result<U, E>>(
self,
f: F,
) -> Result<SortOrderPushdownResult<U>, E> {
match self {
Self::Exact { inner } => {
Ok(SortOrderPushdownResult::Exact { inner: f(inner)? })
}
Self::Inexact { inner } => {
Ok(SortOrderPushdownResult::Inexact { inner: f(inner)? })
}
Self::Unsupported => Ok(SortOrderPushdownResult::Unsupported),
}
}
pub fn into_inexact(self) -> Self {
match self {
Self::Exact { inner } => Self::Inexact { inner },
Self::Inexact { inner } => Self::Inexact { inner },
Self::Unsupported => Self::Unsupported,
}
}
}