pub trait Plugin:
Send
+ Sync
+ 'static {
type Ctx: Send + 'static;
const ENTRIES: &'static [&'static str];
const ASYNC_ENTRIES: &'static [&'static str] = _;
// Required methods
fn new() -> Self
where Self: Sized;
fn new_ctx(&self) -> Self::Ctx;
fn on_call(&self, session: &mut Session<'_>, ctx: &mut Self::Ctx) -> Reply;
// Provided methods
fn on_async_call(
&self,
session: AsyncSession,
ctx: Self::Ctx,
) -> impl Future<Output = Reply> + Send { ... }
fn spawn_async(&self, task: AsyncTask) { ... }
fn on_stream_data(&self, _sid: u64, _data: &[u8]) -> NrStatus { ... }
fn on_stream_close(&self, _sid: u64) -> NrStatus { ... }
fn on_shutdown(&self) { ... }
}Expand description
A nylon-ring plugin. Implement this and export it with
export_plugin!; see the module docs for the state model.
Required Associated Constants§
Sourceconst ENTRIES: &'static [&'static str]
const ENTRIES: &'static [&'static str]
Entry names dispatched to Plugin::on_call. An entry’s dispatch
id is its index here, so appending keeps existing ids stable.
Provided Associated Constants§
Sourceconst ASYNC_ENTRIES: &'static [&'static str] = _
const ASYNC_ENTRIES: &'static [&'static str] = _
Entry names dispatched to Plugin::on_async_call. Their dispatch
ids continue after Plugin::ENTRIES (a name in both lists
dispatches synchronously).
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn on_async_call(
&self,
session: AsyncSession,
ctx: Self::Ctx,
) -> impl Future<Output = Reply> + Send
fn on_async_call( &self, session: AsyncSession, ctx: Self::Ctx, ) -> impl Future<Output = Reply> + Send
Handles one ASYNC_ENTRIES call. The ABI
callback returns Ok immediately; the reply is delivered whenever
the returned future completes, from whatever thread runs it — the
host’s standard async path supports this deferred, cross-thread
reply natively. Implement with plain async fn syntax; no
async_trait crate is needed.
Reply::Fail is sent to the host as a result (so an awaiting
caller fails instead of hanging); Reply::None sends nothing.
Sourcefn spawn_async(&self, task: AsyncTask)
fn spawn_async(&self, task: AsyncTask)
Runs an async handler’s task. Only futures that are still pending
after their first poll arrive here — ready-on-first-poll handlers
deliver inline on the host thread and never touch the executor.
The default drives the task on a dedicated thread with a
park/unpark waker — correct, dependency-free, and fine for
occasional calls. Override with a real executor for throughput,
e.g. tokio::spawn(task); on a runtime the plugin owns (stop it in
Plugin::on_shutdown).
Sourcefn on_stream_data(&self, _sid: u64, _data: &[u8]) -> NrStatus
fn on_stream_data(&self, _sid: u64, _data: &[u8]) -> NrStatus
Data the host pushes into a plugin-consumed stream.
Sourcefn on_stream_close(&self, _sid: u64) -> NrStatus
fn on_stream_close(&self, _sid: u64) -> NrStatus
The host closed a plugin-consumed stream.
Sourcefn on_shutdown(&self)
fn on_shutdown(&self)
Runs when the host shuts the plugin down; stop worker threads here.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".