Summary
io::writer.write returns uint64, so the common statement form output.write(data); always triggers K7010 Expression result is unused. The warning is technically correct, but it makes the normal “write these bytes” path noisy unless every caller stores and checks the count.
Motivation
The byte-oriented writer capability is intentionally minimal (write(byte[])), but its return-value shape is awkward in ordinary code:
void write_bytes(io::writer output, byte[] data) {
output.write(data); // warning K7010: Expression result is unused.
}
Callers must write:
uint64 written = output.write(data);
if (written != data.len()) {
// handle short write
}
even when short-write handling is not relevant to the example or application. This makes io::writer examples noisier and can teach users to silence warnings without thinking about partial writes.
Possible directions
- Add a higher-level
write_all(...) convenience API that returns void and handles/retries short writes or reports failure through the language's error model.
- Add an explicit discard form (for example
_ = expr; or discard expr;) so intentional result-dropping is visible and warning-free.
- Keep
write(...) uint64 as the low-level primitive, but document the recommended ergonomic wrapper.
Context
The byte[]-only surface is not the issue; it keeps encoding explicit through txt::utf8.encode / txt::gbk.encode. This request is only about the ergonomics of the returned byte count and K7010.
Summary
io::writer.writereturnsuint64, so the common statement formoutput.write(data);always triggersK7010 Expression result is unused. The warning is technically correct, but it makes the normal “write these bytes” path noisy unless every caller stores and checks the count.Motivation
The byte-oriented writer capability is intentionally minimal (
write(byte[])), but its return-value shape is awkward in ordinary code:Callers must write:
even when short-write handling is not relevant to the example or application. This makes
io::writerexamples noisier and can teach users to silence warnings without thinking about partial writes.Possible directions
write_all(...)convenience API that returnsvoidand handles/retries short writes or reports failure through the language's error model._ = expr;ordiscard expr;) so intentional result-dropping is visible and warning-free.write(...) uint64as the low-level primitive, but document the recommended ergonomic wrapper.Context
The byte[]-only surface is not the issue; it keeps encoding explicit through
txt::utf8.encode/txt::gbk.encode. This request is only about the ergonomics of the returned byte count andK7010.