Skip to content

Commit 21d6b51

Browse files
committed
added blanket type conversion
1 parent 465c5c5 commit 21d6b51

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/metadata/extra_tags.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
use crate::error::{AsyncTiffError, AsyncTiffResult};
22
use crate::tiff::tags::Tag;
33
use crate::tiff::Value;
4+
use std::any::Any;
45
use std::collections::{HashMap, HashSet};
56
use std::fmt::Debug;
67
use 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
2629
where
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

Comments
 (0)