@@ -22,7 +22,7 @@ pub fn Cache(comptime K: type, comptime V: type) type {
2222 };
2323
2424 /// Initialize cache with given capacity.
25- pub fn init (allocator : std.mem.Allocator , capacity : u32 ) ! Self {
25+ pub fn init (allocator : std.mem.Allocator , capacity : u32 ) std.mem.Allocator.Error ! Self {
2626 var self : Self = .{};
2727 try self .map .ensureTotalCapacity (allocator , capacity );
2828 return self ;
@@ -53,7 +53,7 @@ pub fn Cache(comptime K: type, comptime V: type) type {
5353
5454 /// Put node pointer and return `true` if associated key is not already present.
5555 /// Otherwise, put node pointer, evicting old entry, and return `false`.
56- pub fn put (self : * Self , node : * Node ) ! bool {
56+ pub fn put (self : * Self , node : * Node ) bool {
5757 if (self .map .getPtr (node .key )) | old_node | {
5858 node .is_visited = true ;
5959 old_node .* = node ;
@@ -132,13 +132,13 @@ test Cache {
132132 var flipflop_node : StringCache.Node = .{ .key = "flip" , .value = "flop" };
133133 var ticktock_node : StringCache.Node = .{ .key = "tick" , .value = "tock" };
134134
135- try std .testing .expect (try cache .put (& zigzag_node ));
136- try std .testing .expect (try cache .put (& foobar_node ));
135+ try std .testing .expect (cache .put (& zigzag_node ));
136+ try std .testing .expect (cache .put (& foobar_node ));
137137
138138 try std .testing .expectEqualStrings ("bar" , cache .fetchRemove ("foo" ).? );
139139
140- try std .testing .expect (try cache .put (& flipflop_node ));
141- try std .testing .expect (try cache .put (& ticktock_node ));
140+ try std .testing .expect (cache .put (& flipflop_node ));
141+ try std .testing .expect (cache .put (& ticktock_node ));
142142
143143 try std .testing .expectEqualStrings ("zag" , cache .get ("zig" ).? );
144144 try std .testing .expectEqual (cache .get ("foo" ), null );
@@ -156,10 +156,10 @@ test Cache {
156156 var foobar_node : StringCache.Node = .{ .key = "foo" , .value = "bar" };
157157 var flipflop_node : StringCache.Node = .{ .key = "flip" , .value = "flop" };
158158
159- try std .testing .expect (try cache .put (& zigzag_node ));
160- try std .testing .expect (try cache .put (& foobar_node ));
161- try std .testing .expect (! try cache .put (& zigupd_node ));
162- try std .testing .expect (try cache .put (& flipflop_node ));
159+ try std .testing .expect (cache .put (& zigzag_node ));
160+ try std .testing .expect (cache .put (& foobar_node ));
161+ try std .testing .expect (! cache .put (& zigupd_node ));
162+ try std .testing .expect (cache .put (& flipflop_node ));
163163
164164 try std .testing .expectEqualStrings ("upd" , cache .get ("zig" ).? );
165165 }
0 commit comments