pub struct ModeId { /* private fields */ }Expand description
Namespaced mode identifier with numeric discriminant.
Modes are identified by their owning module, a local name, and a numeric
discriminant for O(1) identity comparison. The discriminant provides
compile-time type safety when used with the Mode trait.
§Identity
Two ModeIds are equal if and only if their module AND discriminant match.
The name is for display purposes only and does not affect equality.
§Example
use reovim_kernel::api::v1::{ModeId, ModuleId};
let editor_module = ModuleId::new("editor");
let normal = ModeId::with_discriminant(editor_module.clone(), "NORMAL", 0);
let insert = ModeId::with_discriminant(editor_module, "INSERT", 1);
assert_eq!(normal.name(), "NORMAL");
assert_eq!(normal.discriminant(), 0);
assert_eq!(insert.discriminant(), 1);
assert_ne!(normal, insert);Implementations§
Source§impl ModeId
impl ModeId
Sourcepub const fn new(module: ModuleId, name: &'static str) -> Self
pub const fn new(module: ModuleId, name: &'static str) -> Self
Create a new mode identifier with default discriminant (0).
This constructor is provided for backward compatibility.
Prefer with_discriminant for new code.
Sourcepub const fn with_discriminant(
module: ModuleId,
name: &'static str,
discriminant: u16,
) -> Self
pub const fn with_discriminant( module: ModuleId, name: &'static str, discriminant: u16, ) -> Self
Create a new mode identifier with explicit discriminant.
The discriminant should be unique within the module and stable across versions for serialization compatibility.
Sourcepub const fn discriminant(&self) -> u16
pub const fn discriminant(&self) -> u16
Get the numeric discriminant.
Trait Implementations§
Source§impl<M: Mode> From<M> for ModeId
Blanket implementation: all Mode types convert to ModeId.
impl<M: Mode> From<M> for ModeId
Blanket implementation: all Mode types convert to ModeId.
This allows ergonomic usage:
let stack = ModeStack::new(VimMode::Normal); // No .into() needed
stack.push(VimMode::Insert);