Skip to main content

ModuleContext

Struct ModuleContext 

Source
pub struct ModuleContext {
    pub kernel: KernelContext,
    pub services: Arc<ServiceRegistry>,
    pub data_dir: PathBuf,
    pub cache_dir: PathBuf,
    /* private fields */
}
Expand description

Context provided to modules during initialization.

Extends KernelContext with module-specific paths for data and cache storage, plus access to the cross-module service registry. This is passed to Module::init() and provides everything a module needs to initialize itself.

§Example

use reovim_kernel::api::v1::{Module, ModuleContext, ProbeResult};

impl Module for MyModule {
    fn init(&mut self, ctx: &ModuleContext) -> ProbeResult {
        // Access kernel services
        let bus = &ctx.kernel.event_bus;

        // Access module-specific directories
        let config_path = ctx.data_dir.join("config.toml");
        let cache_path = ctx.cache_dir.join("cache.bin");

        // Register services for other modules to discover
        ctx.services.register(Arc::new(MyService::new()));

        ProbeResult::Success
    }
}

Fields§

§kernel: KernelContext

Kernel context for core services.

§services: Arc<ServiceRegistry>

Service registry for cross-module service discovery.

Modules can register their services here during init() for other modules to discover. See ServiceRegistry for usage patterns.

§data_dir: PathBuf

Module’s data directory (persistent storage).

e.g., ~/.local/share/reovim/modules/<module-id>/

§cache_dir: PathBuf

Module’s cache directory (ephemeral storage).

e.g., ~/.cache/reovim/modules/<module-id>/

Implementations§

Source§

impl ModuleContext

Source

pub fn new( kernel: KernelContext, services: Arc<ServiceRegistry>, data_dir: PathBuf, cache_dir: PathBuf, ) -> Self

Create a new module context.

Source

pub fn with_optional_deps( kernel: KernelContext, services: Arc<ServiceRegistry>, data_dir: PathBuf, cache_dir: PathBuf, loaded_optional_deps: Vec<ModuleId>, ) -> Self

Create a module context with optional dependencies info.

Source

pub fn has_optional_dep(&self, id: &ModuleId) -> bool

Check if an optional dependency was loaded.

§Example
use reovim_kernel::api::v1::{ModuleContext, ModuleId};

fn init(ctx: &ModuleContext) {
    if ctx.has_optional_dep(&ModuleId::new("lsp")) {
        // Enable LSP integration
    }
}
Source

pub fn optional_deps(&self) -> &[ModuleId]

Get all loaded optional dependencies.

Returns a slice of ModuleIds for optional dependencies that were successfully loaded before this module’s initialization.

§Example
use reovim_kernel::api::v1::ModuleContext;

fn init(ctx: &ModuleContext) {
    for dep in ctx.optional_deps() {
        println!("Optional dep available: {}", dep.as_str());
    }
}

Trait Implementations§

Source§

impl Clone for ModuleContext

Source§

fn clone(&self) -> ModuleContext

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ModuleContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ModuleContext

Source§

fn default() -> Self

Create a default ModuleContext for testing purposes.

Uses stub implementations and temporary directories. Should only be used in tests where context fields are not accessed.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.