Under heavy development. This site describes the intended 1.0 language. Current features and performance vary. Development status
Sn50SnThe SnAPI programming language
0.2.0 Preview 1 · Frozen documentation

WriteAll

Completes a byte write through bounded sequential short operations. Stops on error, validates every reported count and preserves the already transferred prefix. Zero-length input performs no source operation. No allocation, synchronization or hidden flush is introduced.

Sn is under heavy development. Reference extracted from this release’s bundled standard library. Public API examples are not an exhaustive compatibility test. Read the matching release guide for tested workflows and limitations. Read the status →

Module std.io

import std.io;

Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.

WriteAll

pub fn WriteAll<S>(Source: mut S&, Input: readonly byte[]) -> Result<void, IoError>
    where S: Writer

Completes a byte write through bounded sequential short operations. Stops on error, validates every reported count and preserves the already transferred prefix. Zero-length input performs no source operation. No allocation, synchronization or hidden flush is introduced. S: Concrete mutable Writer stream. Source: Borrowed mutable stream for this synchronous operation. Input: Borrowed readonly bytes for the complete transfer. Return: Ok only at requested length; error carries proven transferred prefix. Warning: Provider operations may block; source views may not escape the call.

Example

module example.exact_io;
from std.io import ReadExactly, WriteAll, IoError;
from std.prelude import Result;
struct ShortReader {
    pub Count: usize;
    pub init() { this.Count = 0; }
    pub fn Read(Output: mut byte[]) -> Result<usize, IoError> {
        if Output.Length == 0 || this.Count == 3 { return .Ok { Value = 0 }; }
        Output[0] = 0x61_byte; this.Count += 1; return .Ok { Value = 1 };
    }
}
struct ShortWriter {
    pub Count: usize;
    pub init() { this.Count = 0; }
    pub fn Write(Input: readonly byte[]) -> Result<usize, IoError> {
        if Input.Length == 0 { return .Ok { Value = 0 }; }
        this.Count += 1; return .Ok { Value = 1 };
    }
    pub fn Flush() -> Result<void, IoError> { return .Ok; }
}
fn Main() -> i32 {
    var Reader = ShortReader(); var Writer = ShortWriter();
    var Bytes: byte[3] = [0_byte, 0_byte, 0_byte];
    if ReadExactly(Reader, Bytes) is .Err { Error = _ } { return 1; }
    if WriteAll(Writer, Bytes) is .Err { Error = _ } { return 2; }
    if Writer.Flush() is .Err { Error = _ } { return 3; }
    if Reader.Count != 3 || Writer.Count != 3 || Bytes[2] != 0x61_byte { return 4; }
    var Extra: byte[1] = [0_byte];
    switch ReadExactly(Reader, Extra) {
        case .Err { Error = Failure } => {
            // Inspect each enum layer with one direct payload pattern.
            switch Failure {
                case .Failure { Reason = Reason, Transferred = Count } if (Reason is .UnexpectedEof) => { if Count != 0 { return 5; } }
                default => return 6;
            }
        }
        default => return 6;
    }
    return 0;
}
Documentation snapshot: October 24, 2026 About versions ↗
Searching Development · language & standard library