plugy_core/
lib.rs

1//! # plugy-core
2//!
3//! This crate contains fundamental components and utilities that serve as the building blocks for
4//! plugy's dynamic plugin system. It provides essential functionalities that enable seamless integration
5//! of plugins into your Rust applications using WebAssembly (Wasm).
6//! 
7//!
8//! ## Modules
9//!
10//! - [`bitwise`](bitwise/index.html): A module providing utilities for working with bitwise operations and conversions.
11//! - [`guest`](guest/index.html): A module that facilitates communication between the host application and Wasm plugins.
12//!
13
14use std::{pin::Pin, future::Future};
15pub mod bitwise;
16pub mod guest;
17
18/// A trait for loading plugin module data asynchronously.
19///
20/// This trait defines the behavior for loading plugin module data asynchronously.
21/// Implementors of this trait provide the ability to asynchronously retrieve
22/// the Wasm module data for a plugin.
23///
24pub trait PluginLoader {
25    /// Asynchronously loads the Wasm module data for the plugin.
26    ///
27    /// This method returns a `Future` that produces a `Result` containing
28    /// the Wasm module data as a `Vec<u8>` on success, or an `anyhow::Error`
29    /// if loading encounters issues.
30    ///
31    /// # Returns
32    ///
33    /// Returns a `Pin<Box<dyn Future<Output = Result<Vec<u8>, anyhow::Error>>>>`
34    /// representing the asynchronous loading process.
35    fn bytes(&self) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, anyhow::Error>>>>;
36
37    /// A plugins name should be known before loading.
38    /// It might just be `std::any::type_name::<Self>()`
39    fn name(&self) -> &'static str;
40}