rio_rs/registry/identifiable_type.rs
1//! Trait object registry
2//!
3//! Provides storage for objects and maps their callables to handle registered message types
4
5use std::any::type_name;
6
7/// Define a name for a given Struct so it can be used at runtime.
8///
9/// By default this will use [std::any::type_name] (which might not be compatible across all your
10/// infrastructure), so it is advised to implement your own 'user_defined_type_id'
11///
12/// <div class="warning">This won't deal with duplicates. But the registry takes care of it</div>
13pub trait IdentifiableType {
14 fn user_defined_type_id() -> &'static str {
15 type_name::<Self>()
16 }
17
18 /// Same as IdentifiableType::user_defined_type_id, but it can be
19 /// called directly from the struct instance. This is handy for when
20 /// one uses impl Trait instead of generic
21 fn instance_type_id(&self) -> &'static str {
22 Self::user_defined_type_id()
23 }
24}