Files
aji/tests/conformance/source/buffered_io/writer_zero.aji
T
dev 8d8bef8f3e cli: add explicit owning buffered file adapters
Add pinned std.io.reader and std.io.writer using safe source, explicit fixed
allocation and file transfer. Finish/discard return complete resources;
writer failures preserve pending data and prohibit unsound partial retries.

Specify cursor, acceptance, failure and cleanup contracts in spec 16,
RFC 0034, the API reference and source bundle. Add standalone conformance,
independent byte oracles, task/GC stress, CLI/package/profile checks and
hosted partial-write tests with a raised child quota to detect retries.

Validation: 1061 conformance cases; 34 buffered cases with per-step GC and
12 schedule seeds; unit/Quick Reference, formatting, hosted smoke,
89 CLI checks, 115 source coverage constructs and reference generation.
2026-10-07 12:38:55 +03:00

33 lines
2.1 KiB
Rust

// expect: run
// result: 42
// phase: 6
// spec: docs/spec/16-standard-library.md §2.18
// grant: dst=fs.write:/out
// grant: heap=mem.alloc:0
// file: /out/data=abc
module test.buffered
import std.io;
import std.io.reader;
import std.io.writer;
import std.option;
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
}
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
}
fn exact(result: std.io.ReadExactResult) -> void effects [] {
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
}
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
}
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
}
fn main(dst: cap<fs.write>,heap: cap<mem.alloc>) -> u64 effects [fs.write,mem.alloc] {
let file = fs.create(dst,b"/out/data") or trap; let value = writer(move file,0usize,heap); { mut q = value; written(std.io.writer.write(q,b"abc")); match std.io.writer.flush(q) { std.io.writer.FlushResult::ok => {}, std.io.writer.FlushResult::err(error) => { trap; } } }
fs.close(finished_writer(move value)) or trap; return 42;
}