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) !...@@ -179,7 +179,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !
179 if (try extras.doesFolderExist(null, pv)) {179 if (try extras.doesFolderExist(null, pv)) {
180 return pv;180 return pv;
181 }181 }
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, "/")).?;
183 if (d.version.len > 0) {183 if (d.version.len > 0) {
184 if (try extras.doesFolderExist(null, pv)) {184 if (try extras.doesFolderExist(null, pv)) {
185 return pv;185 return pv;
src/util/funcs.zig+2-4
...@@ -79,10 +79,8 @@ pub fn list_remove(alloc: std.mem.Allocator, input: []string, search: string) ![...@@ -79,10 +79,8 @@ pub fn list_remove(alloc: std.mem.Allocator, input: []string, search: string) ![
79 return list.toOwnedSlice();79 return list.toOwnedSlice();
80}80}
8181
82pub fn last(in: []string) !string {82pub fn last(in: []string) ?string {
83 if (in.len == 0) {83 if (in.len == 0) return null;
84 return error.EmptyArray;
85 }
86 return in[in.len - 1];84 return in[in.len - 1];
87}85}
8886