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