如何从第三方模块重新导出函数

And*_*ltz 2 zig

我有一个有用的模块,但我想在不修改foo.zig它的情况下为其添加更多功能,因此我创建了一个具有一两个以上功能的模块,并且具有数十个功能。foo-wrapper.zigfoo.zig

我如何将所有功能重新导出(使用pub或某种东西)给foo.zig的所有消费者foo-wrapper.zig

Ali*_*ghi 5

只需声明函数名称foo-wrapper.zig并添加pub关键字即可。


foo.zig

pub fn hello() void {
 std.debug.print("Hello", .{});
}
Run Code Online (Sandbox Code Playgroud)

foo-wrapper.zig

const foo = @import("foo.zig");
pub const hello = foo.hello;
// or do
pub usingnamespace @import("foo.zig");

pub fn helloWorld() void {
 hello();
 std.debug.print(" World", .{});
}
Run Code Online (Sandbox Code Playgroud)

主程序.zig

const foo_wrapper = @import("foo-wrapper.zig");

pub fn main() void {
  foo_wrapper.helloWorld();
  foo_wrapper.hello();
}
Run Code Online (Sandbox Code Playgroud)