Skip to main content

reovim_driver_session/
handler_key.rs

1//! Session handler key - typed key for session handler lookup.
2//!
3//! Defines the typed key enum for session handler discovery.
4
5use reovim_kernel::api::v1::ServiceKey;
6
7/// Typed key for session handler lookup.
8///
9/// This enum defines the purposes for which session handlers can be registered.
10/// Currently only `Empty` is supported for handling sessions without buffers.
11///
12/// # Compile-Time Safety
13///
14/// Using typed keys instead of strings ensures:
15/// - Typos are caught at compile time (`SessionHandlerKey::Emtpy` → error)
16/// - Exhaustive matching in `match` statements
17/// - Self-documenting API
18///
19/// # Example
20///
21/// ```ignore
22/// use reovim_driver_session::{SessionHandlerKey, SessionHandlerRegistry, EmptySessionHandler};
23/// use std::sync::Arc;
24///
25/// let registry = SessionHandlerRegistry::new();
26/// registry.register(SessionHandlerKey::Empty, Arc::new(ScratchBufferHandler::new()));
27///
28/// // Lookup with typed key
29/// let handler = registry.get(&SessionHandlerKey::Empty);
30/// ```
31#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
32pub enum SessionHandlerKey {
33    /// Handler for empty sessions (no buffers).
34    ///
35    /// When a session starts with no files specified, this handler
36    /// determines what to do (e.g., create a scratch buffer, show welcome).
37    Empty,
38}
39
40impl ServiceKey for SessionHandlerKey {
41    fn service_name() -> &'static str {
42        "SessionHandler"
43    }
44}
45#[cfg(test)]
46#[path = "handler_key_tests.rs"]
47mod tests;