1
1
use crate :: error:: { AsyncTiffError , AsyncTiffResult } ;
2
2
use crate :: tiff:: tags:: Tag ;
3
3
use crate :: tiff:: Value ;
4
+ use std:: any:: Any ;
4
5
use std:: collections:: { HashMap , HashSet } ;
5
6
use std:: fmt:: Debug ;
6
7
use std:: sync:: Arc ;
7
8
8
9
/// Trait to implement for custom tags, such as Geo, EXIF, OME, etc
9
10
/// your type should also implement `Clone`
10
11
// 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 {
12
13
/// a list of tags this entry processes
13
14
/// e.g. for Geo this would be [34735, 34736, 34737]
14
15
fn tags ( & self ) -> & ' static [ Tag ] ;
@@ -18,17 +19,23 @@ pub trait ExtraTags: ExtraTagsCloneArc + std::any::Any + Debug + Send + Sync {
18
19
19
20
// we need to do a little dance to do an object-safe deep clone
20
21
// https://stackoverflow.com/a/30353928/14681457
21
- pub trait ExtraTagsCloneArc {
22
+ // also object-safe type conversions for downcasting
23
+ pub trait ExtraTagsBlankets {
22
24
fn clone_arc ( & self ) -> Arc < dyn ExtraTags > ;
25
+ fn as_any_arc ( self : Arc < Self > ) -> Arc < dyn Any + Send + Sync > ;
23
26
}
24
27
25
- impl < T > ExtraTagsCloneArc for T
28
+ impl < T > ExtraTagsBlankets for T
26
29
where
27
30
T : ' static + ExtraTags + Clone ,
28
31
{
29
32
fn clone_arc ( & self ) -> Arc < dyn ExtraTags > {
30
33
Arc :: new ( self . clone ( ) )
31
34
}
35
+
36
+ fn as_any_arc ( self : Arc < Self > ) -> Arc < dyn Any + Send + Sync > {
37
+ self
38
+ }
32
39
}
33
40
34
41
/// The registry in which extra tags (parsers) are registered
0 commit comments