use crate::core::store::random_access_input::RandomAccessInput;
use crate::core::util::error::lucene_error::{LuceneError, Result};
use crate::core::util::packed::direct_reader::FromSlice;
pub trait LongValues {
fn get_mut(&mut self, _index: usize) -> Result<i64> {
Err(LuceneError::not_implemented(
"mutable get method not implement",
))
}
fn get(&self, _index: usize) -> Result<i64> {
Err(LuceneError::not_implemented(
"Immutable get method not implement",
))
}
}
pub struct Identity;
impl LongValues for Identity {
fn get_mut(&mut self, index: usize) -> Result<i64> {
Ok(index as i64)
}
fn get(&self, index: usize) -> Result<i64> {
Ok(index as i64)
}
}
pub struct Zeroes;
impl LongValues for Zeroes {
fn get_mut(&mut self, _index: usize) -> Result<i64> {
Ok(0)
}
fn get(&self, _index: usize) -> Result<i64> {
Ok(0)
}
}
impl<R> FromSlice<R> for Zeroes
where
R: RandomAccessInput,
{
fn read_from_slice(&mut self, _index: usize, _slice: Option<&R>) -> Result<i64> {
Ok(0)
}
}
macro_rules! either_long_values {
($vis:vis $name:ident { $( $Variant:ident : $T:ident ),+ $(,)? }) => {
$vis enum $name<$( $T ),+> {
$( $Variant($T), )+
}
impl<$( $T ),+> LongValues for $name<$( $T ),+>
where
$( $T: LongValues ),+
{
fn get_mut(&mut self, index: usize) -> Result<i64> {
match self {
$( Self::$Variant(inner) => inner.get_mut(index), )+
}
}
fn get(&self, index: usize) -> Result<i64> {
match self {
$( Self::$Variant(inner) => inner.get(index), )+
}
}
}
};
}
either_long_values!(pub LongValuesEnum2 { A: A, B: B });
either_long_values!(pub LongValuesEnum3 { A: A, B: B, C:C });
either_long_values!(pub LongValuesEnum6 { A:A,B:B,C:C,D:D,E:E,F:F });
either_long_values!(pub LongValuesEnum16 { A:A,B:B,C:C,D:D,E:E,F:F,G:G,H:H,I:I,J:J,K:K,L:L,M:M,N:N,O:O,P:P});