字段
std.Build.Cache.Directory.Allocator
别名
别名目标 std.mem.Allocator
std.Build.Cache.Directory.assert
别名
别名目标 std.debug.assert
std.Build.Cache.Directory.clone
函数
pub fn clone(d: Directory, arena: Allocator) Allocator.Error!Directory
参数
错误
- OutOfMemory
std.Build.Cache.Directory.closeAndFree
函数
是否应关闭句柄或释放路径由 具体使用方式决定;若调用方恰有此需求, 则可使用此便利函数。
pub fn closeAndFree(self: *Directory, gpa: Allocator, io: Io) void
参数
std.Build.Cache.Directory.cwd
函数
pub fn cwd() Directory
std.Build.Cache.Directory.Directory
别名
std.Build.Cache.Directory.eql
函数
pub fn eql(self: Directory, other: Directory) bool
参数
std.Build.Cache.Directory.fmt
别名
别名目标 std.fmt
std.Build.Cache.Directory.format
函数
pub fn format(self: Directory, writer: *std.Io.Writer) std.Io.Writer.Error!void
参数
错误
- WriteFailed
详细诊断信息见
Writer实现。
std.Build.Cache.Directory.fs
别名
别名目标 std.fs
std.Build.Cache.Directory.Io
别名
别名目标 std.Io
std.Build.Cache.Directory.join
函数
pub fn join(self: Directory, allocator: Allocator, paths: []const []const u8) ![]u8
参数
std.Build.Cache.Directory.joinZ
函数
pub fn joinZ(self: Directory, allocator: Allocator, paths: []const []const u8) ![:0]u8
参数
std.Build.Cache.Directory.std
别名
别名目标 std
源码
std/Build/Cache/Directory.zig
const Directory = @This();
const std = @import("../../std.zig");
const Io = std.Io;
const fs = std.fs;
const assert = std.debug.assert;
const fmt = std.fmt;
const Allocator = std.mem.Allocator;
/// 对于可直接操作已打开目录句柄的操作,此字段冗余,
/// 但将目录传给子进程时需要使用它。
/// `null` 表示当前工作目录。
path: ?[]const u8,
handle: Io.Dir,
pub fn clone(d: Directory, arena: Allocator) Allocator.Error!Directory {
return .{
.path = if (d.path) |p| try arena.dupe(u8, p) else null,
.handle = d.handle,
};
}
pub fn cwd() Directory {
return .{
.path = null,
.handle = .cwd(),
};
}
pub fn join(self: Directory, allocator: Allocator, paths: []const []const u8) ![]u8 {
if (self.path) |p| {
// TODO: 寻找仅需一次分配的简洁实现
const part2 = try fs.path.join(allocator, paths);
defer allocator.free(part2);
return fs.path.join(allocator, &[_][]const u8{ p, part2 });
} else {
return fs.path.join(allocator, paths);
}
}
pub fn joinZ(self: Directory, allocator: Allocator, paths: []const []const u8) ![:0]u8 {
if (self.path) |p| {
// TODO: 寻找仅需一次分配的简洁实现
const part2 = try fs.path.join(allocator, paths);
defer allocator.free(part2);
return fs.path.joinZ(allocator, &[_][]const u8{ p, part2 });
} else {
return fs.path.joinZ(allocator, paths);
}
}
/// 是否应关闭句柄或释放路径由
/// 具体使用方式决定;若调用方恰有此需求,
/// 则可使用此便利函数。
pub fn closeAndFree(self: *Directory, gpa: Allocator, io: Io) void {
self.handle.close(io);
if (self.path) |p| gpa.free(p);
self.* = undefined;
}
pub fn format(self: Directory, writer: *std.Io.Writer) std.Io.Writer.Error!void {
if (self.path) |p| {
try writer.writeAll(p);
try writer.writeAll(fs.path.sep_str);
}
}
pub fn eql(self: Directory, other: Directory) bool {
return self.handle.handle == other.handle.handle;
}