pub trait Registered {
// Required method
fn type_id() -> &'static str;
// Provided method
fn supports_type_id(type_id: &str) -> bool { ... }
}Expand description
Trait for types that can be registered in a Registry.
Provides a unique type identifier for runtime type checking. This trait
is implemented by both Store types and
TransportConfig types.
§Example
use eidetica::Registered;
struct MyType;
impl Registered for MyType {
fn type_id() -> &'static str {
"mytype:v0"
}
}
assert_eq!(MyType::type_id(), "mytype:v0");
assert!(MyType::supports_type_id("mytype:v0"));
assert!(!MyType::supports_type_id("other:v0"));Required Methods§
Provided Methods§
Sourcefn supports_type_id(type_id: &str) -> bool
fn supports_type_id(type_id: &str) -> bool
Check if this type supports loading from a stored type_id.
Override this method to support version migration, allowing newer implementations to read data stored by older versions.
§Example
use eidetica::Registered;
struct MyTypeV1;
impl Registered for MyTypeV1 {
fn type_id() -> &'static str {
"mytype:v1"
}
fn supports_type_id(type_id: &str) -> bool {
// v1 can read both v0 and v1 data
type_id == "mytype:v0" || type_id == "mytype:v1"
}
}
assert_eq!(MyTypeV1::type_id(), "mytype:v1");
assert!(MyTypeV1::supports_type_id("mytype:v0")); // Can read v0
assert!(MyTypeV1::supports_type_id("mytype:v1")); // Can read v1
assert!(!MyTypeV1::supports_type_id("other:v0")); // Cannot read other typesDyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.