@@ -4,6 +4,7 @@ use crate::tiff::Value;
4
4
use std:: any:: Any ;
5
5
use std:: collections:: { HashMap , HashSet } ;
6
6
use std:: fmt:: Debug ;
7
+ use std:: ops:: Index ;
7
8
use std:: sync:: Arc ;
8
9
9
10
/// Trait to implement for custom tags, such as Geo, EXIF, OME, etc
@@ -13,8 +14,8 @@ pub trait ExtraTags: ExtraTagsBlankets + Any + Debug + Send + Sync {
13
14
/// a list of tags this entry processes
14
15
/// e.g. for Geo this would be [34735, 34736, 34737]
15
16
fn tags ( & self ) -> & ' static [ Tag ] ;
16
- /// process a single tag
17
- fn process_tag ( & mut self , tag : u16 , value : Value ) -> AsyncTiffResult < ( ) > ;
17
+ /// process a single tag, using internal mutability if needed
18
+ fn process_tag ( & self , tag : Tag , value : Value ) -> AsyncTiffResult < ( ) > ;
18
19
}
19
20
20
21
// we need to do a little dance to do an object-safe deep clone
@@ -48,6 +49,10 @@ impl ExtraTagsRegistry {
48
49
pub fn new ( ) -> Self {
49
50
Self ( HashMap :: new ( ) )
50
51
}
52
+ /// checks if we have an entry for this tag
53
+ pub fn contains ( & self , tag : & Tag ) -> bool {
54
+ self . 0 . contains_key ( tag)
55
+ }
51
56
/// Register an ExtraTags so their tags are parsed and stored in the ifd's `extra_tags``
52
57
pub fn register ( & mut self , tags : Arc < dyn ExtraTags > ) -> AsyncTiffResult < ( ) > {
53
58
// check for duplicates
@@ -91,6 +96,13 @@ impl Default for ExtraTagsRegistry {
91
96
}
92
97
}
93
98
99
+ impl Index < & Tag > for ExtraTagsRegistry {
100
+ type Output = Arc < dyn ExtraTags > ;
101
+ fn index ( & self , index : & Tag ) -> & Self :: Output {
102
+ & self . 0 [ index]
103
+ }
104
+ }
105
+
94
106
#[ cfg( test) ]
95
107
mod tests {
96
108
use super :: * ;
@@ -112,8 +124,8 @@ mod tests {
112
124
}
113
125
114
126
fn process_tag (
115
- & mut self ,
116
- tag : u16 ,
127
+ & self ,
128
+ tag : Tag ,
117
129
value : crate :: tiff:: Value ,
118
130
) -> crate :: error:: AsyncTiffResult < ( ) > {
119
131
println ! ( "received {tag:?}: {value:?}" ) ;
0 commit comments