1use crate::core::{Blob, Id, PlacedPoint, Point};
11
12pub type PlaceResult<T> = Result<T, PlaceError>;
14
15#[derive(Debug, Clone, PartialEq)]
17pub enum PlaceError {
18 DimensionalityMismatch { expected: usize, got: usize },
20
21 CapacityExceeded,
23
24 DuplicateId(Id),
26
27 StorageError(String),
29}
30
31impl std::fmt::Display for PlaceError {
32 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33 match self {
34 PlaceError::DimensionalityMismatch { expected, got } => {
35 write!(f, "Dimensionality mismatch: expected {}, got {}", expected, got)
36 }
37 PlaceError::CapacityExceeded => write!(f, "Storage capacity exceeded"),
38 PlaceError::DuplicateId(id) => write!(f, "Duplicate ID: {}", id),
39 PlaceError::StorageError(msg) => write!(f, "Storage error: {}", msg),
40 }
41 }
42}
43
44impl std::error::Error for PlaceError {}
45
46pub trait Place: Send + Sync {
50 fn place(&mut self, point: Point, blob: Blob) -> PlaceResult<Id>;
54
55 fn place_with_id(&mut self, id: Id, point: Point, blob: Blob) -> PlaceResult<()>;
59
60 fn remove(&mut self, id: Id) -> Option<PlacedPoint>;
64
65 fn get(&self, id: Id) -> Option<&PlacedPoint>;
69
70 fn contains(&self, id: Id) -> bool {
72 self.get(id).is_some()
73 }
74
75 fn len(&self) -> usize;
77
78 fn is_empty(&self) -> bool {
80 self.len() == 0
81 }
82
83 fn iter(&self) -> Box<dyn Iterator<Item = &PlacedPoint> + '_>;
85
86 fn size_bytes(&self) -> usize;
88
89 fn clear(&mut self);
91}