diff --git a/honeycomb-core/src/attributes/manager.rs b/honeycomb-core/src/attributes/manager.rs index d8691bea..498aa254 100644 --- a/honeycomb-core/src/attributes/manager.rs +++ b/honeycomb-core/src/attributes/manager.rs @@ -9,7 +9,7 @@ use stm::{StmResult, Transaction}; use super::{AttributeBind, AttributeStorage, AttributeUpdate, UnknownAttributeStorage}; use crate::{ - cmap::CMapResult, + cmap::{CMapError, CMapResult}, prelude::{DartIdType, OrbitPolicy}, }; use std::{any::TypeId, collections::HashMap}; @@ -162,7 +162,7 @@ impl AttrStorageManager { /// # Panics /// /// This function will panic if there is already a storage of attribute `A` in the manager. - pub fn add_storage(&mut self, size: usize) { + pub fn add_storage(&mut self, size: usize) -> CMapResult<()> { let typeid = TypeId::of::(); let new_storage = ::StorageType::new(size); if match A::BIND_POLICY { @@ -177,12 +177,9 @@ impl AttrStorageManager { } .is_some() { - eprintln!( - "W: Storage of attribute `{}` already exists in the attribute storage manager", - std::any::type_name::() - ); - eprintln!(" Continuing..."); + return Err(CMapError::DuplicateAttribute(std::any::type_name::())); } + Ok(()) } /// Extend the size of the storage of a given attribute. @@ -194,15 +191,13 @@ impl AttrStorageManager { /// ## Generic /// /// - `A: AttributeBind` -- Attribute of which the storage should be extended. - pub fn extend_storage(&mut self, length: usize) { + pub fn extend_storage(&mut self, length: usize) -> CMapResult<()> { get_storage_mut!(self, storage); if let Some(st) = storage { st.extend(length); + Ok(()) } else { - eprintln!( - "W: could not extend storage of attribute {} - storage not found", - std::any::type_name::() - ); + Err(CMapError::UnknownAttribute(std::any::type_name::())) } } @@ -218,14 +213,16 @@ impl AttrStorageManager { /// - there's no storage associated with the specified attribute /// - downcasting `Box` to `::StorageType` fails #[must_use = "unused getter result - please remove this method call"] - pub fn get_storage(&self) -> Option<&::StorageType> { + pub fn get_storage(&self) -> CMapResult<&::StorageType> { let probably_storage = match A::BIND_POLICY { OrbitPolicy::Vertex | OrbitPolicy::VertexLinear => &self.vertices[&TypeId::of::()], OrbitPolicy::Edge => &self.edges[&TypeId::of::()], OrbitPolicy::Face | OrbitPolicy::FaceLinear => &self.faces[&TypeId::of::()], OrbitPolicy::Custom(_) => &self.others[&TypeId::of::()], }; - probably_storage.downcast_ref::<::StorageType>() + probably_storage + .downcast_ref::<::StorageType>() + .ok_or(CMapError::UnknownAttribute(std::any::type_name::())) } /// Remove an entire attribute storage from the manager. @@ -627,11 +624,7 @@ impl AttrStorageManager { if let Some(st) = storage { st.try_merge(trans, id_out, id_in_lhs, id_in_rhs) } else { - eprintln!( - "W: could not update storage of attribute {} - storage not found", - std::any::type_name::() - ); - Ok(()) + Err(CMapError::UnknownAttribute(std::any::type_name::())) } } } @@ -1018,11 +1011,7 @@ impl AttrStorageManager { if let Some(st) = storage { st.try_split(trans, id_out_lhs, id_out_rhs, id_in) } else { - eprintln!( - "W: could not update storage of attribute {} - storage not found", - std::any::type_name::() - ); - Ok(()) + Err(CMapError::UnknownAttribute(std::any::type_name::())) } } } diff --git a/honeycomb-core/src/cmap/error.rs b/honeycomb-core/src/cmap/error.rs index f94d4633..71ad87b7 100644 --- a/honeycomb-core/src/cmap/error.rs +++ b/honeycomb-core/src/cmap/error.rs @@ -20,6 +20,9 @@ pub enum CMapError { /// Geometry check failed. #[error("operation incompatible with map geometry: {0}")] IncorrectGeometry(&'static str), + /// Attribute already in the map storage. + #[error("duplicate attribute: {0}")] + DuplicateAttribute(&'static str), /// Accessed attribute isn't in the map storage. #[error("unknown attribute: {0}")] UnknownAttribute(&'static str),