11use crate :: error:: { AsyncTiffError , AsyncTiffResult } ;
22use crate :: tiff:: tags:: Tag ;
33use crate :: tiff:: Value ;
4+ use std:: any:: Any ;
45use std:: collections:: { HashMap , HashSet } ;
56use std:: fmt:: Debug ;
67use std:: sync:: Arc ;
78
89/// Trait to implement for custom tags, such as Geo, EXIF, OME, etc
910/// your type should also implement `Clone`
1011// Send + Sync are required for Python, where `dyn ExtraTags` needs `Send` and `Sync`
11- pub trait ExtraTags : ExtraTagsCloneArc + std :: any :: Any + Debug + Send + Sync {
12+ pub trait ExtraTags : ExtraTagsBlankets + Any + Debug + Send + Sync {
1213 /// a list of tags this entry processes
1314 /// e.g. for Geo this would be [34735, 34736, 34737]
1415 fn tags ( & self ) -> & ' static [ Tag ] ;
@@ -18,17 +19,23 @@ pub trait ExtraTags: ExtraTagsCloneArc + std::any::Any + Debug + Send + Sync {
1819
1920// we need to do a little dance to do an object-safe deep clone
2021// https://stackoverflow.com/a/30353928/14681457
21- pub trait ExtraTagsCloneArc {
22+ // also object-safe type conversions for downcasting
23+ pub trait ExtraTagsBlankets {
2224 fn clone_arc ( & self ) -> Arc < dyn ExtraTags > ;
25+ fn as_any_arc ( self : Arc < Self > ) -> Arc < dyn Any + Send + Sync > ;
2326}
2427
25- impl < T > ExtraTagsCloneArc for T
28+ impl < T > ExtraTagsBlankets for T
2629where
2730 T : ' static + ExtraTags + Clone ,
2831{
2932 fn clone_arc ( & self ) -> Arc < dyn ExtraTags > {
3033 Arc :: new ( self . clone ( ) )
3134 }
35+
36+ fn as_any_arc ( self : Arc < Self > ) -> Arc < dyn Any + Send + Sync > {
37+ self
38+ }
3239}
3340
3441/// The registry in which extra tags (parsers) are registered
0 commit comments