Skip to content

enhancement: make io::writer.write result easier to consume without K7010 noise #162

Description

@sentomk

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions