| |
| |
| |
| |
| |
| |
| |
| |
|
|
| use crate::core::{Blob, Id, PlacedPoint, Point}; |
|
|
| |
| pub type PlaceResult<T> = Result<T, PlaceError>; |
|
|
| |
| #[derive(Debug, Clone, PartialEq)] |
| pub enum PlaceError { |
| |
| DimensionalityMismatch { expected: usize, got: usize }, |
|
|
| |
| CapacityExceeded, |
|
|
| |
| DuplicateId(Id), |
|
|
| |
| StorageError(String), |
| } |
|
|
| impl std::fmt::Display for PlaceError { |
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| match self { |
| PlaceError::DimensionalityMismatch { expected, got } => { |
| write!(f, "Dimensionality mismatch: expected {}, got {}", expected, got) |
| } |
| PlaceError::CapacityExceeded => write!(f, "Storage capacity exceeded"), |
| PlaceError::DuplicateId(id) => write!(f, "Duplicate ID: {}", id), |
| PlaceError::StorageError(msg) => write!(f, "Storage error: {}", msg), |
| } |
| } |
| } |
|
|
| impl std::error::Error for PlaceError {} |
|
|
| |
| |
| |
| pub trait Place: Send + Sync { |
| |
| |
| |
| fn place(&mut self, point: Point, blob: Blob) -> PlaceResult<Id>; |
|
|
| |
| |
| |
| fn place_with_id(&mut self, id: Id, point: Point, blob: Blob) -> PlaceResult<()>; |
|
|
| |
| |
| |
| fn remove(&mut self, id: Id) -> Option<PlacedPoint>; |
|
|
| |
| |
| |
| fn get(&self, id: Id) -> Option<&PlacedPoint>; |
|
|
| |
| fn contains(&self, id: Id) -> bool { |
| self.get(id).is_some() |
| } |
|
|
| |
| fn len(&self) -> usize; |
|
|
| |
| fn is_empty(&self) -> bool { |
| self.len() == 0 |
| } |
|
|
| |
| fn iter(&self) -> Box<dyn Iterator<Item = &PlacedPoint> + '_>; |
|
|
| |
| fn size_bytes(&self) -> usize; |
|
|
| |
| fn clear(&mut self); |
| } |
|
|