在Rust的动态加载库的结构中调用关联的功能

发布于 2025-02-05 03:30:14 字数 855 浏览 2 评论 0 原文

我已经使用Rust-embed设置了以下基础架构:

板条板A:

  • 构建 dylib .so file),该 file)使用派生的宏来在编译时间加载文件到结构。
#[derive(RustEmbed)]
#[folder = "./src"]
struct Asset;

代码和更多文档在这里:

在这种情况下,它将所有文件加载到该板条箱的 ./ src 中。

板条板B:

  • 从板条箱中加载构建的 .so 使用 libloading 的文件,其中包括以下类型: type loadAssetAssetFunc = fn() - >资产;
  • 应该能够调用资产:: get get Rustembed derive acro中定义),

但是即使我我正在返回资产在结构或 box 中使用 ./ src 文件,因此它正在使用struct 资产在板条板B中,它也使用了衍生宏,并且在板条箱中不使用 Asset 的构造,该板条箱中加载了该板条箱中的文件。我如何确保它使用 Asset a而不是b?

I have setup the following infrastructure using rust-embed:

Crate A:

  • Builds a dylib (.so file) which uses a derive macro to load files at compile time to a struct.
#[derive(RustEmbed)]
#[folder = "./src"]
struct Asset;

Code and more documentation is here: https://github.com/pyrossh/rust-embed#documentation

In this case it loads all the files within ./src of that crate.

Crate B:

  • Loads the built .so file from crate A using libloading with the following type: type LoadAssetFunc = fn() -> Asset;
  • Should be able to call Asset::get (get is defined in the RustEmbed derive macro)

However even if I am returning Asset within a struct or a Box it'll use the ./src files within the current crate, so it is using the struct of Asset within Crate B which also uses the derive macro and it is not using the struct of Asset within Crate A which loaded the files within that crate. How can I make sure it is using Asset of Crate A and not B?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文