pub trait ServiceKey:
Hash
+ Eq
+ Clone
+ Send
+ Sync
+ 'static {
// Required method
fn service_name() -> &'static str;
}Expand description
Marker trait for typed service keys.
Each driver defines its own key enum implementing this trait. This ensures compile-time safety and provides metadata for error messages.
§Safety Contract
DO NOT use service_name() for:
- Runtime service routing or comparison
- Dynamic dispatch based on string matching
- Escape hatch to bypass typed key lookup
The service_name() method exists ONLY for human-readable error messages.
All service lookup MUST use the typed key directly via get(key).
§Correct Usage
ⓘ
// GOOD: Direct typed key lookup
let vfs = registry.get(&VfsScheme::File);§Incorrect Usage
ⓘ
// BAD: Never compare service_name() for routing
if K::service_name() == "VFS" { ... } // WRONG!
// BAD: Never use as escape hatch
fn get_any_service(name: &str) { ... } // WRONG!§Example
ⓘ
use reovim_kernel::api::v1::ServiceKey;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum VfsScheme {
File,
Memory,
Ssh,
}
impl ServiceKey for VfsScheme {
fn service_name() -> &'static str { "VFS" }
}Required Methods§
Sourcefn service_name() -> &'static str
fn service_name() -> &'static str
Human-readable service name for error messages ONLY.
NOT for comparison or routing. See trait-level docs.
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.