Draft specification, RFCs, reference registries and examples, plus the reference-implementation skeleton: build.zig, diagnostic envelope with error-code registry synced to docs, aji CLI, conformance runner with seed tests, CI and contributor docs.
33 lines
750 B
Rust
33 lines
750 B
Rust
module examples.file_copy;
|
|
|
|
fn copy(
|
|
fs_read: cap<fs.read>,
|
|
fs_write: cap<fs.write>,
|
|
src: slice<u8>,
|
|
dst: slice<u8>,
|
|
alloc: cap<mem.alloc>
|
|
) -> Result<void, IoError>
|
|
effects [mem.alloc, fs.read, fs.write]
|
|
{
|
|
let input = fs.open_read(fs_read, src)?;
|
|
defer fs.close(move input);
|
|
|
|
let output = fs.open_write(fs_write, dst)?;
|
|
defer fs.close(move output);
|
|
|
|
var region = region.create(alloc, limit = 64 KiB)?;
|
|
defer region.destroy(move region);
|
|
|
|
let buffer = region.alloc_zeroed_array<u8>(mut region, 64 KiB)?;
|
|
|
|
while true {
|
|
let n = fs.read(ref input, buffer)?;
|
|
if n == 0 {
|
|
break;
|
|
}
|
|
fs.write_all(ref output, slice.prefix(buffer, n))?;
|
|
}
|
|
|
|
return Ok();
|
|
}
|