fix: fixing doctest issues with auto_plugin macro

This commit is contained in:
Byson94
2025-10-12 13:08:20 +05:30
parent 9a37ab6e7b
commit dcdcc2dbc5
2 changed files with 16 additions and 37 deletions

View File

@@ -10,6 +10,8 @@
/// easily make plugins in a single step.
///
/// ```rust
/// use ewwii_plugin_api::auto_plugin;
///
/// auto_plugin!(MyPluginName, {
/// // host variable is passed in automatically
/// host.log("Easy, huh?");
@@ -17,37 +19,10 @@
///
/// ```
///
/// That's it! The plugin is ready.
///
/// ## When not to use it
///
/// This macro shall not be used if you want to have
/// fields in your plugin.
///
/// ```rust
/// struct MyPluginName {
/// awesome_field: String
/// }
/// ```
///
/// For a structure like the above, you should do this instead:
///
/// ```rust
/// use ewwii_plugin_api::{EwwiiAPI, Plugin, export_plugin};
///
/// pub struct DummyStructure;
///
/// impl Plugin for DummyStructure {
/// // critical for ewwii to launch the plugin
/// fn init(&self, host: &dyn EwwiiAPI) {
/// // will be printed by the host
/// host.log("Plugin says Hello!");
/// }
/// }
///
/// // Critical for ewwii to load the plugin
/// export_plugin!(DummyStructure);
/// ```
/// This macro shall not be used if you prefer flexibility and safety.
/// The manual approach is verbose, but is way safer and flexible than using this macro.
#[macro_export]
macro_rules! auto_plugin {
($struct_name:ident, $init_block:block) => {

View File

@@ -50,10 +50,12 @@ pub trait EwwiiAPI: Send + Sync {
/// # Example
///
/// ```rust
/// host.rhai_engine_action(Box::new(|eng| {
/// // eng = rhai::Engine
/// eng.set_max_expr_depths(128, 128);
/// }));
/// fn init(&self, host: &dyn EwwiiAPI) {
/// host.rhai_engine_action(Box::new(|eng| {
/// // eng = rhai::Engine
/// eng.set_max_expr_depths(128, 128);
/// }));
/// }
/// ```
#[cfg(feature = "include-rhai")]
fn rhai_engine_action(&self, f: Box<dyn FnOnce(&mut Engine) + Send>) -> Result<(), String>;
@@ -67,10 +69,12 @@ pub trait EwwiiAPI: Send + Sync {
/// # Example
///
/// ```rust
/// host.widget_reg_action(Box::new(|wrg| {
/// // wrg = widget_backend::WidgetRegistryRepr
/// // The gtk4::Widget can be modified here.
/// }));
/// fn init(&self, host: &dyn EwwiiAPI) {
/// host.widget_reg_action(Box::new(|wrg| {
/// // wrg = widget_backend::WidgetRegistryRepr
/// // The gtk4::Widget can be modified here.
/// }));
/// }
/// ```
#[cfg(feature = "include-gtk4")]
fn widget_reg_action(