master
1const std = @import("std");
2const Allocator = std.mem.Allocator;
3const expect = std.testing.expect;
4
5test "using an allocator" {
6 var buffer: [100]u8 = undefined;
7 var fba = std.heap.FixedBufferAllocator.init(&buffer);
8 const allocator = fba.allocator();
9 const result = try concat(allocator, "foo", "bar");
10 try expect(std.mem.eql(u8, "foobar", result));
11}
12
13fn concat(allocator: Allocator, a: []const u8, b: []const u8) ![]u8 {
14 const result = try allocator.alloc(u8, a.len + b.len);
15 @memcpy(result[0..a.len], a);
16 @memcpy(result[a.len..], b);
17 return result;
18}
19
20// test