Env API Reference
The main environment store. Owns all allocated memory.
Initialization
Env.init
pub fn init(allocator: std.mem.Allocator, cfg: Config) EnvCreate a new empty Env instance.
Env.deinit
pub fn deinit(self: *Env) voidFree all resources. Must be called when done.
Loading
load
pub fn load(self: *Env, path: []const u8) !voidLoad and parse a .env file from disk.
parseString
pub fn parseString(self: *Env, source: []const u8) !voidParse a .env string and add entries.
loadMany
pub fn loadMany(self: *Env, paths: []const []const u8) !voidLoad multiple .env files in order. Later files override earlier ones.
reload
pub fn reload(self: *Env, path: []const u8) !voidClear all entries and reload from a file.
Reading Values
get
pub fn get(self: *const Env, key: []const u8) ?[]const u8Get a value by key. Returns null if not found.
getString
pub fn getString(self: *const Env, key: []const u8) ?[]const u8Alias for get.
getBool
pub fn getBool(self: *const Env, key: []const u8) ?boolGet a boolean value. Accepts: true/false/yes/no/1/0/on/off.
getInt
pub fn getInt(self: *const Env, comptime T: type, key: []const u8) ?TGet an integer value of the specified type.
getFloat
pub fn getFloat(self: *const Env, comptime T: type, key: []const u8) ?TGet a float value.
getEnum
pub fn getEnum(self: *const Env, comptime E: type, key: []const u8) ?EGet an enum value from a string.
getList
pub fn getList(self: *const Env, allocator: std.mem.Allocator, key: []const u8, delimiter: u8) ?[][]const u8Get a list of values by splitting on a delimiter.
contains
pub fn contains(self: *const Env, key: []const u8) boolCheck if a key exists.
Writing & Updating Values
set
pub fn set(self: *Env, key: []const u8, value: []const u8) !voidSet a key-value pair. If the key already exists, the value is updated. If the key doesn't exist, a new entry is created.
// Add new entry
try env.set("API_KEY", "secret123");
// Update existing entry
try env.set("PORT", "9090");merge
pub fn merge(self: *Env, other: *const Env) !voidMerge another Env into this one. Entries from other override existing ones.
try env.merge(&defaults);Deleting Values
remove
pub fn remove(self: *Env, key: []const u8) boolRemove a key-value pair. Returns true if the key existed, false otherwise.
if (env.remove("DEBUG")) {
std.debug.print("Removed DEBUG\n", .{});
}clear
pub fn clear(self: *Env) voidRemove all entries.
env.clear();Iteration
count
pub fn count(self: *const Env) usizeGet the number of entries.
keys
pub fn keys(self: *const Env) []const []const u8Get all keys in insertion order.
iterator
pub fn iterator(self: *const Env) IteratorCreate an iterator over entries.
Serialization
serialize
pub fn serialize(self: *const Env) ![]const u8Serialize entries to .env format.
save
pub fn save(self: *const Env, path: []const u8) !voidWrite entries to a file.
Utilities
clone
pub fn clone(self: *const Env) !EnvCreate an independent deep copy.
validate
pub fn validate(self: *const Env, s: schema_mod.Schema) []ValidationErrorValidate entries against a schema.
