1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
use std::{any::Any, sync::Arc};
use crate::{PluginGcConfig, PluginIdentity, PluginMetadata, ShellError};
/// Trait for plugins registered in the [`EngineState`](crate::engine::EngineState).
pub trait RegisteredPlugin: Send + Sync {
/// The identity of the plugin - its filename, shell, and friendly name.
fn identity(&self) -> &PluginIdentity;
/// True if the plugin is currently running.
fn is_running(&self) -> bool;
/// Process ID of the plugin executable, if running.
fn pid(&self) -> Option<u32>;
/// Get metadata for the plugin, if set.
fn metadata(&self) -> Option<PluginMetadata>;
/// Set metadata for the plugin.
fn set_metadata(&self, metadata: Option<PluginMetadata>);
/// Set garbage collection config for the plugin.
fn set_gc_config(&self, gc_config: &PluginGcConfig);
/// Stop the plugin.
fn stop(&self) -> Result<(), ShellError>;
/// Stop the plugin and reset any state so that we don't make any assumptions about the plugin
/// next time it launches. This is used on `register`.
fn reset(&self) -> Result<(), ShellError>;
/// Cast the pointer to an [`Any`] so that its concrete type can be retrieved.
///
/// This is necessary in order to allow `nu_plugin` to handle the implementation details of
/// plugins.
fn as_any(self: Arc<Self>) -> Arc<dyn Any + Send + Sync>;
}