@@ -4,6 +4,7 @@ use crate::tiff::Value;
44use std:: any:: Any ;
55use std:: collections:: { HashMap , HashSet } ;
66use std:: fmt:: Debug ;
7+ use std:: ops:: Index ;
78use std:: sync:: Arc ;
89
910/// Trait to implement for custom tags, such as Geo, EXIF, OME, etc
@@ -13,8 +14,8 @@ pub trait ExtraTags: ExtraTagsBlankets + Any + Debug + Send + Sync {
1314 /// a list of tags this entry processes
1415 /// e.g. for Geo this would be [34735, 34736, 34737]
1516 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 < ( ) > ;
1819}
1920
2021// we need to do a little dance to do an object-safe deep clone
@@ -48,6 +49,10 @@ impl ExtraTagsRegistry {
4849 pub fn new ( ) -> Self {
4950 Self ( HashMap :: new ( ) )
5051 }
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+ }
5156 /// Register an ExtraTags so their tags are parsed and stored in the ifd's `extra_tags``
5257 pub fn register ( & mut self , tags : Arc < dyn ExtraTags > ) -> AsyncTiffResult < ( ) > {
5358 // check for duplicates
@@ -91,6 +96,13 @@ impl Default for ExtraTagsRegistry {
9196 }
9297}
9398
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+
94106#[ cfg( test) ]
95107mod tests {
96108 use super :: * ;
@@ -112,8 +124,8 @@ mod tests {
112124 }
113125
114126 fn process_tag (
115- & mut self ,
116- tag : u16 ,
127+ & self ,
128+ tag : Tag ,
117129 value : crate :: tiff:: Value ,
118130 ) -> crate :: error:: AsyncTiffResult < ( ) > {
119131 println ! ( "received {tag:?}: {value:?}" ) ;
0 commit comments