From 14b4d3f5cd4deb4eee4162b3bb2f6032a285913b Mon Sep 17 00:00:00 2001 From: polygon Date: Mon, 5 Dec 2022 23:39:43 +0000 Subject: [PATCH] Adapt path type of dynamically_load_plugin (#6734) # Objective - Fixes #6711 ## Solution - Change the `path` function parameter of `dynamically_load_plugin` and `DynamicPluginExt::load_plugin` to a generic with `AsRef` bound --- crates/bevy_dynamic_plugin/src/loader.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/bevy_dynamic_plugin/src/loader.rs b/crates/bevy_dynamic_plugin/src/loader.rs index 046bc1165be016..50f2bb34cb0725 100644 --- a/crates/bevy_dynamic_plugin/src/loader.rs +++ b/crates/bevy_dynamic_plugin/src/loader.rs @@ -1,4 +1,5 @@ use libloading::{Library, Symbol}; +use std::ffi::OsStr; use thiserror::Error; use bevy_app::{App, CreatePlugin, Plugin}; @@ -20,8 +21,8 @@ pub enum DynamicPluginLoadError { /// The specified plugin must be linked against the exact same libbevy.so as this program. /// In addition the `_bevy_create_plugin` symbol must not be manually created, but instead created /// by deriving `DynamicPlugin` on a unit struct implementing [`Plugin`]. -pub unsafe fn dynamically_load_plugin( - path: &str, +pub unsafe fn dynamically_load_plugin>( + path: P, ) -> Result<(Library, Box), DynamicPluginLoadError> { let lib = Library::new(path).map_err(DynamicPluginLoadError::Library)?; let func: Symbol = lib @@ -35,11 +36,11 @@ pub trait DynamicPluginExt { /// # Safety /// /// Same as [`dynamically_load_plugin`]. - unsafe fn load_plugin(&mut self, path: &str) -> &mut Self; + unsafe fn load_plugin>(&mut self, path: P) -> &mut Self; } impl DynamicPluginExt for App { - unsafe fn load_plugin(&mut self, path: &str) -> &mut Self { + unsafe fn load_plugin>(&mut self, path: P) -> &mut Self { let (lib, plugin) = dynamically_load_plugin(path).unwrap(); std::mem::forget(lib); // Ensure that the library is not automatically unloaded plugin.build(self);