Skip to main content

trait_kit/core/
capability.rs

1// Copyright © 2026 Kirky.X. All rights reserved.
2
3//! Capability key trait for identifying and typing capabilities.
4
5/// The key trait for identifying capabilities in Kit.
6///
7/// Each capability is identified by a unique key type that implements this trait.
8/// The `Capability` associated type specifies the trait object type of the capability.
9/// The `NAME` constant provides a diagnostic name for error messages.
10///
11/// # Type Constraints
12///
13/// The `Capability` type must satisfy:
14/// - `?Sized` — allows trait objects like `dyn SomeTrait`
15/// - `Send + Sync + 'static` — required for thread-safe storage in Kit
16///
17/// The key type itself must satisfy `'static` for TypeId stability.
18///
19/// # Example
20///
21/// ```
22/// use trait_kit::core::capability::CapabilityKey;
23///
24/// struct MyKey;
25/// impl CapabilityKey for MyKey {
26///     type Capability = dyn Send + Sync;
27///     const NAME: &'static str = "my_key";
28/// }
29///
30/// let _ = MyKey::NAME;
31/// ```
32pub trait CapabilityKey: 'static {
33    /// The capability trait object type.
34    /// Must satisfy `?Sized + Send + Sync + 'static`.
35    type Capability: ?Sized + Send + Sync + 'static;
36
37    /// The diagnostic name for this capability key.
38    /// Used in error messages like `MissingCapability { key: "main_logger" }`.
39    const NAME: &'static str;
40}