waynr commented on code in PR #7160:
URL: https://github.com/apache/arrow-rs/pull/7160#discussion_r1964722563
##########
object_store/src/extensions.rs:
##########
@@ -0,0 +1,35 @@
+use std::{
+ any::{Any, TypeId},
+ collections::HashMap,
+ sync::Arc,
+};
+
+type ExtensionMap = HashMap<TypeId, Ext>;
+type Ext = Arc<dyn Any + Send + Sync + 'static>;
+
+#[derive(Debug, Default, Clone)]
+pub struct Extensions {
+ inner: ExtensionMap,
+}
+
+impl Extensions {
+ fn set_ext<T: Send + Sync + 'static>(&mut self, t: T) {
+ let id = t.type_id();
+ let a = Arc::new(t);
+ self.inner.insert(id, a);
+ }
+
+ fn get_ext<T: Send + Sync + 'static>(&self) -> Option<Arc<T>> {
+ let id = TypeId::of::<T>();
+ self.inner
+ .get(&id)
+ .cloned()
+ .map(|e| Arc::downcast(e).expect("TypeId is always unique"))
+ }
+}
+
+impl From<HashMap<TypeId, Ext>> for Extensions {
Review Comment:
Actually, I figured out what I was doing wrong. I was trying to make
`ExtWrapper` generic (ie `ExtWrapper<T>` but there's no reason to do that. I've
fixed it now.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]