std.io.Error
Valuetype pub copy enum ErrorAn error type for I/O operations.
This type is typically constructed from raw OS error codes such as ENOENT on
Unix systems. This enum doesn't define a constructor for every possible error.
Instead, we define a constructor for the most commonly used errors, and
represent other errors using the Other constructor.
Constructors
AddressInUse
AddressInUse()The address is already in use.
AddressUnavailable
AddressUnavailable()The address isn't available.
AlreadyConnected
AlreadyConnected()A connection is already established.
AlreadyExists
AlreadyExists()A resource already exists.
BadAddress
BadAddress()A memory address used (e.g. as an argument) is in an invalid range.
BrokenPipe
BrokenPipe()The operation failed because a pipe was closed.
ConnectionAborted
ConnectionAborted()The connection was aborted by the remote server.
ConnectionRefused
ConnectionRefused()The connection was refused by the remote server.
ConnectionReset
ConnectionReset()The connection was reset by the remote server.
CrossDeviceLink
CrossDeviceLink()A file couldn't be renamed, linked or copied because the operation takes places across different devices.
Deadlock
Deadlock()An operation would result in a deadlock.
DirectoryNotEmpty
DirectoryNotEmpty()A directory isn't empty.
FileTooLarge
FileTooLarge()A file is too large.
HostUnreachable
HostUnreachable()The remote host is unreachable.
InProgress
InProgress()The operation is in progress.
Interrupted
Interrupted()The operation was interrupted.
InvalidArgument
InvalidArgument()One or more arguments are invalid.
InvalidFileDescriptor
InvalidFileDescriptor()A file descriptor is invalid.
InvalidFileName
InvalidFileName()The file name is invalid.
InvalidSeek
InvalidSeek()The seek operation is invalid.
IsADirectory
IsADirectory()The resource is a directory.
NetworkDown
NetworkDown()The network is down.
NotADirectory
NotADirectory()The resource isn't a directory.
NotConnected
NotConnected()A connection isn't established.
NotFound
NotFound()The resource isn't found.
NotSupported
NotSupported()The operation isn't supported.
Other
Other(Int)An error not covered by the other constructor.
The wrapped Int is the raw error code.
OutOfMemory
OutOfMemory()The operation failed because not enough memory could be allocated.
PermissionDenied
PermissionDenied()The operation failed because it lacked the necessary privileges.
ReadOnlyFilesystem
ReadOnlyFilesystem()The filesystem is read-only.
ResourceBusy
ResourceBusy()The resource is busy.
StorageFull
StorageFull()The underlying storage is full.
TimedOut
TimedOut()The operation timed out.
WouldBlock
WouldBlock()The operation would block.
Static methods
from_os_error
Show source codeHide source code
fn pub static from_os_error(code: Int) -> Error {
match code {
case libc.EAGAIN -> Error.WouldBlock
case libc.EPERM -> Error.PermissionDenied
case libc.ENOENT -> Error.NotFound
case libc.EINTR -> Error.Interrupted
case libc.ENOMEM -> Error.OutOfMemory
case libc.EACCES -> Error.PermissionDenied
case libc.EBUSY -> Error.ResourceBusy
case libc.EEXIST -> Error.AlreadyExists
case libc.ENOTDIR -> Error.NotADirectory
case libc.EISDIR -> Error.IsADirectory
case libc.EINVAL -> Error.InvalidArgument
case libc.EFBIG -> Error.FileTooLarge
case libc.ENOSPC -> Error.StorageFull
case libc.ESPIPE -> Error.InvalidSeek
case libc.EROFS -> Error.ReadOnlyFilesystem
case libc.EPIPE -> Error.BrokenPipe
case libc.EDEADLK -> Error.Deadlock
case libc.ENAMETOOLONG -> Error.InvalidFileName
case libc.ENOTEMPTY -> Error.DirectoryNotEmpty
case libc.ETIME -> Error.TimedOut
case libc.EADDRINUSE -> Error.AddressInUse
case libc.EADDRNOTAVAIL -> Error.AddressUnavailable
case libc.ENETDOWN -> Error.NetworkDown
case libc.ENETUNREACH -> Error.NetworkDown
case libc.ECONNABORTED -> Error.ConnectionAborted
case libc.ECONNRESET -> Error.ConnectionReset
case libc.EISCONN -> Error.AlreadyConnected
case libc.ENOTCONN -> Error.NotConnected
case libc.ETIMEDOUT -> Error.TimedOut
case libc.ECONNREFUSED -> Error.ConnectionRefused
case libc.EHOSTUNREACH -> Error.HostUnreachable
case libc.EINPROGRESS -> Error.InProgress
case libc.EFAULT -> Error.BadAddress
case libc.EXDEV -> Error.CrossDeviceLink
case libc.ENOTSUP or libc.EOPNOTSUPP -> Error.NotSupported
case libc.EBADF -> Error.InvalidFileDescriptor
case val -> Error.Other(val)
}
}fn pub static from_os_error(code: Int) -> ErrorReturns an Error from a raw OS error code.
last_os_error
Show source codeHide source code
fn pub static last_os_error -> Error {
from_os_error(libc.errno)
}fn pub static last_os_error -> ErrorReturns the last OS error produced by the current OS thread.
Instance methods
!=
Show source codeHide source code
fn pub !=(other: ref Self) -> Bool {
!(self == other)
}fn pub !=(other: ref Self) -> BoolReturns true if self and the given object are not equal to each other.
==
Show source codeHide source code
fn pub ==(other: Error) -> Bool {
match (self, other) {
case (AddressInUse, AddressInUse) -> true
case (AddressUnavailable, AddressUnavailable) -> true
case (AlreadyConnected, AlreadyConnected) -> true
case (AlreadyExists, AlreadyExists) -> true
case (BrokenPipe, BrokenPipe) -> true
case (ConnectionAborted, ConnectionAborted) -> true
case (ConnectionRefused, ConnectionRefused) -> true
case (ConnectionReset, ConnectionReset) -> true
case (Deadlock, Deadlock) -> true
case (DirectoryNotEmpty, DirectoryNotEmpty) -> true
case (FileTooLarge, FileTooLarge) -> true
case (HostUnreachable, HostUnreachable) -> true
case (InProgress, InProgress) -> true
case (Interrupted, Interrupted) -> true
case (InvalidArgument, InvalidArgument) -> true
case (InvalidFileName, InvalidFileName) -> true
case (InvalidSeek, InvalidSeek) -> true
case (IsADirectory, IsADirectory) -> true
case (NetworkDown, NetworkDown) -> true
case (NotADirectory, NotADirectory) -> true
case (NotConnected, NotConnected) -> true
case (NotFound, NotFound) -> true
case (OutOfMemory, OutOfMemory) -> true
case (PermissionDenied, PermissionDenied) -> true
case (ReadOnlyFilesystem, ReadOnlyFilesystem) -> true
case (ResourceBusy, ResourceBusy) -> true
case (StorageFull, StorageFull) -> true
case (TimedOut, TimedOut) -> true
case (WouldBlock, WouldBlock) -> true
case (Other(a), Other(b)) -> a == b
case (CrossDeviceLink, CrossDeviceLink) -> true
case (NotSupported, NotSupported) -> true
case (InvalidFileDescriptor, InvalidFileDescriptor) -> true
case _ -> false
}
}fn pub ==(other: Error) -> BoolReturns true if self and the given object are equal to each other.
This operator is used to perform structural equality. This means two objects residing in different memory locations may be considered equal, provided their structure is equal. For example, two different arrays may be considered to have structural equality if they contain the exact same values.
fmt
Show source codeHide source code
fn pub fmt(formatter: mut Formatter) {
let name = match self {
case AddressInUse -> 'AddressInUse'
case AddressUnavailable -> 'AddressUnavailable'
case AlreadyConnected -> 'AlreadyConnected'
case AlreadyExists -> 'AlreadyExists'
case BrokenPipe -> 'BrokenPipe'
case ConnectionAborted -> 'ConnectionAborted'
case ConnectionRefused -> 'ConnectionRefused'
case ConnectionReset -> 'ConnectionReset'
case Deadlock -> 'Deadlock'
case DirectoryNotEmpty -> 'DirectoryNotEmpty'
case FileTooLarge -> 'FileTooLarge'
case HostUnreachable -> 'HostUnreachable'
case InProgress -> 'InProgress'
case Interrupted -> 'Interrupted'
case InvalidArgument -> 'InvalidArgument'
case InvalidFileName -> 'InvalidFileName'
case InvalidSeek -> 'InvalidSeek'
case IsADirectory -> 'IsADirectory'
case NetworkDown -> 'NetworkDown'
case NotADirectory -> 'NotADirectory'
case NotConnected -> 'NotConnected'
case NotFound -> 'NotFound'
case OutOfMemory -> 'OutOfMemory'
case PermissionDenied -> 'PermissionDenied'
case ReadOnlyFilesystem -> 'ReadOnlyFilesystem'
case ResourceBusy -> 'ResourceBusy'
case StorageFull -> 'StorageFull'
case TimedOut -> 'TimedOut'
case WouldBlock -> 'WouldBlock'
case BadAddress -> 'BadAddress'
case CrossDeviceLink -> 'CrossDeviceLink'
case NotSupported -> 'NotSupported'
case InvalidFileDescriptor -> 'InvalidFileDescriptor'
case Other(code) -> {
formatter.tuple('Other').field(code).finish
return
}
}
formatter.tuple(name).finish
}fn pub fmt(formatter: mut Formatter)Formats self in a human-readable format for debugging purposes.
to_string
Show source codeHide source code
fn pub to_string -> String {
match self {
case AddressInUse -> 'the address is already in use'
case AddressUnavailable -> "the address isn't available"
case AlreadyConnected -> 'the connection is already established'
case AlreadyExists -> 'the resource already exists'
case BrokenPipe -> 'the operation failed because a pipe was closed'
case ConnectionAborted -> 'the connection was terminated by the server'
case ConnectionRefused -> 'the connection was refused by the server'
case ConnectionReset -> 'the connection was reset by the server'
case Deadlock -> 'the resource would deadlock'
case DirectoryNotEmpty -> "the directory isn't empty"
case FileTooLarge -> 'the file is too large'
case HostUnreachable -> 'the host is unreachable'
case InProgress -> 'the operation is in progress'
case Interrupted -> 'the operation was interrupted'
case InvalidArgument -> 'one or more arguments are invalid'
case InvalidFileName -> 'the file name is too long'
case InvalidSeek -> 'the seek operation is invalid'
case IsADirectory -> 'the resource is a directory'
case NetworkDown -> 'the network is down'
case NotADirectory -> "the resource isn't a directory"
case NotConnected -> "a connection isn't established"
case NotFound -> "the resource isn't found"
case OutOfMemory -> 'we ran out of memory'
case PermissionDenied -> 'the operation lacks the necessary privileges'
case ReadOnlyFilesystem -> 'the file system is read-only'
case ResourceBusy -> 'the resource is busy'
case StorageFull -> 'the storage is full'
case TimedOut -> 'the operation timed out'
case WouldBlock -> 'the operation would block'
case BadAddress -> 'a memory address is in an invalid range'
case CrossDeviceLink -> {
"the operation failed because it can't be performed across devices"
}
case NotSupported -> "the operation isn't supported"
case InvalidFileDescriptor -> 'the file descriptor is invalid'
case Other(code) -> 'an other error with code ${code} occurred'
}
}fn pub to_string -> StringConverts self to a String.
Implemented traits
Equal
impl Equal for ErrorFormat
impl Format for ErrorToString
impl ToString for Error