Development Documentation (main branch) - For stable release docs, see docs.rs/eidetica

Registered

Trait Registered 

Source
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§

Source

fn type_id() -> &'static str

Returns a unique identifier for this type.

The format is typically "name:version" (e.g., "docstore:v0", "iroh:v0").

Provided Methods§

Source

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 types

Dyn 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.

Implementors§