diff --git a/src/stack.zig b/src/stack.zig old mode 100644 new mode 100755 index 2335331..507bfe8 --- a/src/stack.zig +++ b/src/stack.zig @@ -18,8 +18,8 @@ pub const FinitePushError = error { /// pub fn Fixed(comptime Element: type, comptime capacity: usize) type { return struct { - filled: usize = 0, - buffer: [capacity]Element = undefined, + filled: usize, + buffer: [capacity]Element, const Self = @This(); @@ -57,6 +57,16 @@ pub fn Fixed(comptime Element: type, comptime capacity: usize) type { return self.filled; } + /// + /// Creates and returns a [Self] value. + /// + pub fn init() Self { + return Self{ + .filled = 0, + .buffer = undefined, + }; + } + /// /// Attempts to pop the tail-end of `self`, returning the element value or `null` if the /// stack is empty. @@ -137,6 +147,16 @@ pub fn Unmanaged(comptime Element: type) type { return self.filled; } + /// + /// Creates and returns a [Self] value wrapping `buffer` as its writable memory buffer. + /// + pub fn init(buffer: []Element) Self { + return Self{ + .filled = 0, + .buffer = buffer, + }; + } + /// /// Attempts to pop the tail-end of `self`, returning the element value or `null` if the /// stack is empty.