IoError structv0.1.0
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
| Name | Type | Description |
|---|---|---|
kind | IoErrorKind | The meaning every platform shares. |
raw | int32 | The 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.
| Name | Type | Description |
|---|---|---|
kind | IoErrorKind | which kind of failure this is |
Returns: an error of that kind, carrying no platform value
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
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
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.
| Name | Type | Description |
|---|---|---|
writer | &var TextWriter | the destination |
spec | FormatSpec | what the placeholder asked for |
Returns: success when the whole text was accepted
Related
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.
Cases
| Name | Value | Description |
|---|---|---|
EndOfStream | 1 | The stream ended: not a failure, but it arrives where failures do. |
NotFound | 2 | The named thing does not exist. |
PermissionDenied | 3 | The system refused on rights. |
AlreadyExists | 4 | The named thing exists where something new was to be made. |
IsDirectory | 5 | A directory stood where a file was expected. |
NotDirectory | 6 | A file stood where a directory was expected. |
StorageFull | 7 | The device has no room left. |
Interrupted | 8 | The operation was interrupted and may simply be retried. |
WouldBlock | 9 | The operation would block a stream opened not to. |
InvalidHandle | 10 | A handle that is not open, or not open for this. |
InvalidInput | 11 | An argument the system rejected. |
TimedOut | 12 | The operation ran out of time. |
WriteZero | 13 | A write reported fewer bytes than asked and cannot continue. |
InvalidText | 15 | Bytes that were required to be UTF-8 text and are not. |
LimitExceeded | 16 | A bounded operation met its bound before its end. |
ConnectionRefused | 17 | The other end refused the connection: nothing listens there. |
ConnectionReset | 18 | The other end reset the connection. |
ConnectionAborted | 19 | The connection was aborted on this side. |
NotConnected | 20 | The socket is not connected. |
AddressInUse | 21 | The local address is already in use. |
AddressUnavailable | 22 | The address is not one this machine has, or cannot be reached from it. |
Unreachable | 23 | No route leads to the network or host. |
BrokenPipe | 24 | The other end closed the connection, so nothing more can be written to it. |
Other | 14 | Something 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.
| Name | Type | Description |
|---|---|---|
writer | &var TextWriter | the destination |
spec | FormatSpec | what the placeholder asked for |
Returns: success when the whole text was accepted
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.
Parameters
| Name | Type | Description |
|---|---|---|
outcome | ! IoError | what 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.
Parameters
| Name | Type | Description |
|---|---|---|
error | &FormatError | the formatting failure to translate |
Returns: the closest I/O meaning, with no platform code, since none applies