Tidy up code conventions in Stack module

This commit is contained in:
kayomn 2022-09-30 09:48:32 +01:00
parent 677e7be0a2
commit d6782d12d2
1 changed files with 13 additions and 13 deletions

View File

@ -1,17 +1,6 @@
const io = @import("./io.zig");
const std = @import("std");
///
/// Potential errors that may occur while trying to push one or more elements into a stack of a
/// known maximum size.
///
/// [FinitePushError.Overflow] is returned if the stack does not have sufficient capacity to hold a
/// given set of elements.
///
pub const FixedPushError = error {
Overflow,
};
pub fn Fixed(comptime Element: type) type {
return struct {
filled: usize = 0,
@ -24,7 +13,7 @@ pub fn Fixed(comptime Element: type) type {
///
/// Note that this will raise a compilation error if [Element] is not `u8`.
///
pub fn asWriter(self: *Self) io.Writer {
pub fn writer(self: *Self) io.Writer {
if (Element != u8) @compileError("Cannot coerce fixed stack of type " ++
@typeName(Element) ++ " into a Writer");
@ -91,6 +80,17 @@ pub fn Fixed(comptime Element: type) type {
};
}
///
/// Potential errors that may occur while trying to push one or more elements into a stack of a
/// known maximum size.
///
/// [FinitePushError.Overflow] is returned if the stack does not have sufficient capacity to hold a
/// given set of elements.
///
pub const FixedPushError = error {
Overflow,
};
test "fixed stack" {
const testing = @import("std").testing;
const expectError = testing.expectError;
@ -112,7 +112,7 @@ test "fixed stack" {
try expectEqual(stack.count(), 0);
const writer = stack.asWriter();
const writer = stack.writer();
try expectEqual(writer.write(&.{0, 0, 0, 0}), 4);
try expectEqual(writer.writeByte(0), false);