I'm writing a package that allows users (eg, myself) to modify a const during compilation, thus altering the default behaviour of the package. For example:
main.zig
const pkg = import("pkg.zig");
pkg.max_mode = true;
_ = pkg.run(.{});
pkg.zig
pub const max_mode = false; // default
pub const PkgOptions = struct {
max_len: usize = if (!max_mode) 20 else 0,
// ...
}
pub fn run(opt: PkgOptions) bool {
// just some logic that depends on PkgOptions's defaults
return if (opt.max_len != 0) true else false;
}
In the example above, I mocked a package with a predefined set of default options stored in PkgOptions. Depending on the mode set by max_mode, the defaults options are expected to change accordingly. Do you think it is possible to achieve something like that?