use std::error::Error;
use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum AddError {
DimMismatch { existing: usize, got: usize },
DimNotMultipleOf8(usize),
VectorBufferNotMultipleOfDim { vectors_len: usize, dim: usize },
IdsCountMismatch { expected: usize, got: usize },
IdAlreadyPresent(u64),
}
impl fmt::Display for AddError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::DimMismatch { existing, got } => {
write!(f, "dim mismatch: index dim={existing}, batch dim={got}")
}
Self::DimNotMultipleOf8(dim) => {
write!(f, "dim must be a multiple of 8, got {dim}")
}
Self::VectorBufferNotMultipleOfDim { vectors_len, dim } => write!(
f,
"vector buffer length {vectors_len} not a multiple of dim {dim}",
),
Self::IdsCountMismatch { expected, got } => {
write!(f, "expected {expected} ids, got {got}")
}
Self::IdAlreadyPresent(id) => {
write!(f, "id {id} already present in index")
}
}
}
}
impl Error for AddError {}