authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-06-04 10:39:41 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-06-04 10:39:41 -07:00
logdbda0629708d4b34503945ffaeac8674735b44aa
tree6dca0728d7e57cd0dba747d71e38a16ed3d1427f
parent3c223d19106b4bf5670659ebbd4351ab1113175a

'last' is better returning an optional


2 files changed, 3 insertions(+), 5 deletions(-)

src/common.zig+1-1
......@@ -179,7 +179,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !
179179 if (try extras.doesFolderExist(null, pv)) {
180180 return pv;
181181 }
182 const file_name = try u.last(try u.split(options.alloc, d.path, "/"));
182 const file_name = u.last(try u.split(options.alloc, d.path, "/")).?;
183183 if (d.version.len > 0) {
184184 if (try extras.doesFolderExist(null, pv)) {
185185 return pv;
src/util/funcs.zig+2-4
......@@ -79,10 +79,8 @@ pub fn list_remove(alloc: std.mem.Allocator, input: []string, search: string) ![
7979 return list.toOwnedSlice();
8080}
8181
82pub fn last(in: []string) !string {
83 if (in.len == 0) {
84 return error.EmptyArray;
85 }
82pub fn last(in: []string) ?string {
83 if (in.len == 0) return null;
8684 return in[in.len - 1];
8785}
8886