IoError structv0.1.0

Source
A structured I/O failure: the shared meaning, and the platform's own code beside it.
pub struct IoError {
    pub kind: IoErrorKind;
    pub raw: int32;
}

Copy. The raw field is errno on the Unix systems and the Win32 error code on Windows, kept because translation loses detail and the detail is sometimes the diagnosis.

Fields

NameTypeDescription
kindIoErrorKindThe meaning every platform shares.
rawint32The platform's own code, zero where none applies.

Associated functions

Of

pub func Of(kind: IoErrorKind) -> IoError

A failure of kind with no platform code.

NameTypeDescription
kindIoErrorKindwhich kind of failure this is

Returns: an error of that kind, carrying no platform value

Source

Methods

IsEnd

pub func IsEnd(self: &IoError) -> bool

Whether the stream ended, which is the one report that is not a failure.

Returns: whether the stream ended, which is not a failure

Source

IsTransient

pub func IsTransient(self: &IoError) -> bool

Whether going again is the right response: an interruption or a would-block.

Returns: whether trying again could succeed

Source

Implements Display

IoError conforms to Display.

WriteDisplay

pub func WriteDisplay(
    self: &IoError,
    writer: &var TextWriter,
    spec: FormatSpec
) -> ! FormatError

Writes the kind as lower-case words, and the platform's code after them when there is one, as not found (os error 2), under the placeholder's width, fill and alignment. No style is understood. Reports whatever the writer reported, and UnsupportedRequest for a style.

NameTypeDescription
writer&var TextWriterthe destination
specFormatSpecwhat the placeholder asked for

Returns: success when the whole text was accepted

Source

IoErrorKind

pub enum IoErrorKind: int32 {
    EndOfStream = 1,
    NotFound = 2,
    PermissionDenied = 3,
    AlreadyExists = 4,
    IsDirectory = 5,
    NotDirectory = 6,
    StorageFull = 7,
    Interrupted = 8,
    WouldBlock = 9,
    InvalidHandle = 10,
    InvalidInput = 11,
    TimedOut = 12,
    WriteZero = 13,
    InvalidText = 15,
    LimitExceeded = 16,
    ConnectionRefused = 17,
    ConnectionReset = 18,
    ConnectionAborted = 19,
    NotConnected = 20,
    AddressInUse = 21,
    AddressUnavailable = 22,
    Unreachable = 23,
    BrokenPipe = 24,
    Other = 14
}

What an I/O operation reported.

Source

Cases

NameValueDescription
EndOfStream1The stream ended: not a failure, but it arrives where failures do.
NotFound2The named thing does not exist.
PermissionDenied3The system refused on rights.
AlreadyExists4The named thing exists where something new was to be made.
IsDirectory5A directory stood where a file was expected.
NotDirectory6A file stood where a directory was expected.
StorageFull7The device has no room left.
Interrupted8The operation was interrupted and may simply be retried.
WouldBlock9The operation would block a stream opened not to.
InvalidHandle10A handle that is not open, or not open for this.
InvalidInput11An argument the system rejected.
TimedOut12The operation ran out of time.
WriteZero13A write reported fewer bytes than asked and cannot continue.
InvalidText15Bytes that were required to be UTF-8 text and are not.
LimitExceeded16A bounded operation met its bound before its end.
ConnectionRefused17The other end refused the connection: nothing listens there.
ConnectionReset18The other end reset the connection.
ConnectionAborted19The connection was aborted on this side.
NotConnected20The socket is not connected.
AddressInUse21The local address is already in use.
AddressUnavailable22The address is not one this machine has, or cannot be reached from it.
Unreachable23No route leads to the network or host.
BrokenPipe24The other end closed the connection, so nothing more can be written to it.
Other14Something the platform reported that has no shared meaning; the raw code is the detail.

Implements Display

IoErrorKind conforms to Display.

WriteDisplay

pub func WriteDisplay(
    self: &IoErrorKind,
    writer: &var TextWriter,
    spec: FormatSpec
) -> ! FormatError

Writes the kind as lower-case words, such as not found, under the placeholder's width, fill and alignment. No style is understood. Reports whatever the writer reported, and UnsupportedRequest for a style.

NameTypeDescription
writer&var TextWriterthe destination
specFormatSpecwhat the placeholder asked for

Returns: success when the whole text was accepted

Source

FromIoError

pub func FromIoError(outcome: ! IoError) -> ! FormatError

Turns what a stream reported into what a formatter understands. Success becomes the formatter's success value; every failure becomes WriterFailure, which is the only thing FormatError can say about a destination. The details do not travel this way — an adapter records the original IoError where its caller can read it, which is what keeps the loss from being a loss. The end of a stream is a failure here. Nothing is being read, so a write that reports it is a destination that cannot take the bytes, whatever it calls that.

Source

Parameters

NameTypeDescription
outcome! IoErrorwhat the stream reported

Returns: success for a success, and WriterFailure for any failure

ToIoError

pub func ToIoError(error: &FormatError) -> IoError

Turns a formatting failure into something a stream's caller can act on. The distinction that survives is the one worth having: a request that was wrong is InvalidInput and will be wrong again, while a destination that failed came back as an IoError in the first place and never reaches here. Bytes that were not text are InvalidText; a bounded destination that filled is LimitExceeded. WriterFailure should not arrive: an adapter records the stream's own error and its caller reports that instead. It maps to Other rather than being ignored, so an adapter that forgets to keep the original is visibly wrong rather than quietly reporting success.

Source

Parameters

NameTypeDescription
error&FormatErrorthe formatting failure to translate

Returns: the closest I/O meaning, with no platform code, since none applies