make std.mem.toSlice use null terminated pointers

and fix the fallout
This commit is contained in:
Andrew Kelley
2019-11-24 21:12:01 -05:00
parent 34b1ebefaa
commit 15d415e10b
17 changed files with 76 additions and 75 deletions

View File

@@ -72,11 +72,11 @@ pub const Buffer = struct {
self.list.deinit();
}
pub fn toSlice(self: Buffer) []u8 {
pub fn toSlice(self: Buffer) [:0]u8 {
return self.list.toSlice()[0..self.len()];
}
pub fn toSliceConst(self: Buffer) []const u8 {
pub fn toSliceConst(self: Buffer) [:0]const u8 {
return self.list.toSliceConst()[0..self.len()];
}
@@ -131,11 +131,6 @@ pub const Buffer = struct {
try self.resize(m.len);
mem.copy(u8, self.list.toSlice(), m);
}
/// For passing to C functions.
pub fn ptr(self: Buffer) [*]u8 {
return self.list.items.ptr;
}
};
test "simple Buffer" {