oct 0.26.0

Octonary transcodings.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
// Copyright 2024-2025 Gabriel Bjørnager Jensen.
//
// This Source Code Form is subject to the terms of
// the Mozilla Public License, v. 2.0. If a copy of
// the MPL was not distributed with this file, you
// can obtain one at:
// <https://mozilla.org/MPL/2.0/>.

//! The [`ErrorKind`] enumeration.

use core::fmt::{self, Display, Formatter};
use core::hint::unreachable_unchecked;

/// A kind of input/output error.
#[non_exhaustive]
#[derive(
	Clone,
	Copy,
	Debug,
	Eq,
	Hash,
	Ord,
	PartialEq,
	PartialOrd
)]
pub enum ErrorKind {
	/// Address is already in use.
	AddrInUse,

	/// Address is not available.
	AddrNotAvailable,

	/// Path already exists.
	AlreadyExists,

	/// Argument list is too long.
	ArgumentListTooLong,

	/// Pipe is broken.
	BrokenPipe,

	/// Connection has been aborted.
	ConnectionAborted,

	/// Connection has been refused.
	ConnectionRefused,

	/// Connection has been reset.
	ConnectionReset,

	/// Cross-device link.
	CrossesDevices,

	/// Deadlock.
	Deadlock,

	/// Directory is not empty.
	DirectoryNotEmpty,

	/// Executable file is busy.
	ExecutableFileBusy,

	/// File is too large.
	FileTooLarge,

	/// Host is unreachable.
	HostUnreachable,

	/// Operation was interrupted.
	Interrupted,

	/// Invalid data.
	InvalidData,

	/// Invalid file name.
	InvalidFilename,

	/// Invalid input.
	InvalidInput,

	/// Path is a directory.
	IsADirectory,

	/// Network is down.
	NetworkDown,

	/// Network is unreachable.
	NetworkUnreachable,

	/// Path is not a directory.
	NotADirectory,

	/// Connection is missing.
	NotConnected,

	/// Path was not found.
	NotFound,

	/// File is unseekable.
	NotSeekable,

	/// Unknown error.
	Other,

	/// Out of memory.
	OutOfMemory,

	/// Permission was denied.
	PermissionDenied,

	/// Quota has been exceeded.
	QuotaExceeded,

	/// File system is read-only.
	ReadOnlyFilesystem,

	/// Resource is busy.
	ResourceBusy,

	/// Network file handle is stale.
	StaleNetworkFileHandle,

	/// Storage is full.
	StorageFull,

	/// Time out.
	TimedOut,

	/// Too many links.
	TooManyLinks,

	/// Unexpected end of file.
	UnexpectedEof,

	/// Unsupported operation.
	Unsupported,

	/// Operation would block.
	WouldBlock,

	/// Zero write.
	WriteZero,
}

impl ErrorKind {
	/// Constructs an [`ErrorKind`] from an [`usize`]
	/// value.
	///
	/// # Safety
	///
	/// The provided value must originate from an
	/// [`ErrorKind`] object.
	#[inline]
	#[must_use]
	#[track_caller]
	pub(crate) const unsafe fn from_usize_unchecked(value: usize) -> Self {
		const ADDR_IN_USE:               usize = ErrorKind::AddrInUse as usize;
		const ADDR_NOT_AVAILABLE:        usize = ErrorKind::AddrNotAvailable as usize;
		const ALREADY_EXISTS:            usize = ErrorKind::AlreadyExists as usize;
		const ARGUMENT_LIST_TOO_LONG:    usize = ErrorKind::ArgumentListTooLong as usize;
		const BROKEN_PIPE:               usize = ErrorKind::BrokenPipe as usize;
		const CONNECTION_ABORTED:        usize = ErrorKind::ConnectionAborted as usize;
		const CONNECTION_REFUSED:        usize = ErrorKind::ConnectionRefused as usize;
		const CONNECTION_RESET:          usize = ErrorKind::ConnectionReset as usize;
		const CROSSES_DEVICES:           usize = ErrorKind::CrossesDevices as usize;
		const DEADLOCK:                  usize = ErrorKind::Deadlock as usize;
		const DIRECTORY_NOT_EMPTY:       usize = ErrorKind::DirectoryNotEmpty as usize;
		const EXECUTABLE_FILE_BUSY:      usize = ErrorKind::ExecutableFileBusy as usize;
		const FILE_TOO_LARGE:            usize = ErrorKind::FileTooLarge as usize;
		const HOST_UNREACHABLE:          usize = ErrorKind::HostUnreachable as usize;
		const INTERRUPTED:               usize = ErrorKind::Interrupted as usize;
		const INVALID_DATA:              usize = ErrorKind::InvalidData as usize;
		const INVALID_FILENAME:          usize = ErrorKind::InvalidFilename as usize;
		const INVALID_INPUT:             usize = ErrorKind::InvalidInput as usize;
		const IS_A_DIRECTORY:            usize = ErrorKind::IsADirectory as usize;
		const NETWORK_DOWN:              usize = ErrorKind::NetworkDown as usize;
		const NETWORK_UNREACHABLE:       usize = ErrorKind::NetworkUnreachable as usize;
		const NOT_ADIRECTORY:            usize = ErrorKind::NotADirectory as usize;
		const NOT_CONNECTED:             usize = ErrorKind::NotConnected as usize;
		const NOT_FOUND:                 usize = ErrorKind::NotFound as usize;
		const NOT_SEEKABLE:              usize = ErrorKind::NotSeekable as usize;
		const OUT_OF_MEMORY:             usize = ErrorKind::OutOfMemory as usize;
		const PERMISSION_DENIED:         usize = ErrorKind::PermissionDenied as usize;
		const QUOTA_EXCEEDED:            usize = ErrorKind::QuotaExceeded as usize;
		const READ_ONLY_FILESYSTEM:      usize = ErrorKind::ReadOnlyFilesystem as usize;
		const RESOURCE_BUSY:             usize = ErrorKind::ResourceBusy as usize;
		const STALE_NETWORK_FILE_HANDLE: usize = ErrorKind::StaleNetworkFileHandle as usize;
		const STORAGE_FULL:              usize = ErrorKind::StorageFull as usize;
		const TIMED_OUT:                 usize = ErrorKind::TimedOut as usize;
		const TOO_MANY_LINKS:            usize = ErrorKind::TooManyLinks as usize;
		const UNEXPECTED_EOF:            usize = ErrorKind::UnexpectedEof as usize;
		const UNSUPPORTED:               usize = ErrorKind::Unsupported as usize;
		const WOULD_BLOCK:               usize = ErrorKind::WouldBlock as usize;
		const WRITE_ZERO:                usize = ErrorKind::WriteZero as usize;

		match value {
			ADDR_IN_USE               => Self::AddrInUse,
			ADDR_NOT_AVAILABLE        => Self::AddrNotAvailable,
			ALREADY_EXISTS            => Self::AlreadyExists,
			ARGUMENT_LIST_TOO_LONG    => Self::ArgumentListTooLong,
			BROKEN_PIPE               => Self::BrokenPipe,
			CONNECTION_ABORTED        => Self::ConnectionAborted,
			CONNECTION_REFUSED        => Self::ConnectionRefused,
			CONNECTION_RESET          => Self::ConnectionReset,
			CROSSES_DEVICES           => Self::CrossesDevices,
			DEADLOCK                  => Self::Deadlock,
			DIRECTORY_NOT_EMPTY       => Self::DirectoryNotEmpty,
			EXECUTABLE_FILE_BUSY      => Self::ExecutableFileBusy,
			FILE_TOO_LARGE            => Self::FileTooLarge,
			HOST_UNREACHABLE          => Self::HostUnreachable,
			INTERRUPTED               => Self::Interrupted,
			INVALID_DATA              => Self::InvalidData,
			INVALID_FILENAME          => Self::InvalidFilename,
			INVALID_INPUT             => Self::InvalidInput,
			IS_A_DIRECTORY            => Self::IsADirectory,
			NETWORK_DOWN              => Self::NetworkDown,
			NETWORK_UNREACHABLE       => Self::NetworkUnreachable,
			NOT_ADIRECTORY            => Self::NotADirectory,
			NOT_CONNECTED             => Self::NotConnected,
			NOT_FOUND                 => Self::NotFound,
			NOT_SEEKABLE              => Self::NotSeekable,
			OUT_OF_MEMORY             => Self::OutOfMemory,
			PERMISSION_DENIED         => Self::PermissionDenied,
			QUOTA_EXCEEDED            => Self::QuotaExceeded,
			READ_ONLY_FILESYSTEM      => Self::ReadOnlyFilesystem,
			RESOURCE_BUSY             => Self::ResourceBusy,
			STALE_NETWORK_FILE_HANDLE => Self::StaleNetworkFileHandle,
			STORAGE_FULL              => Self::StorageFull,
			TIMED_OUT                 => Self::TimedOut,
			TOO_MANY_LINKS            => Self::TooManyLinks,
			UNEXPECTED_EOF            => Self::UnexpectedEof,
			UNSUPPORTED               => Self::Unsupported,
			WOULD_BLOCK               => Self::WouldBlock,
			WRITE_ZERO                => Self::WriteZero,

			// SAFETY: Caller guarantees this.
			_ => unsafe { unreachable_unchecked() }
		}
	}
}

impl Display for ErrorKind {
	fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
		match *self {
			Self::AddrInUse => {
				write!(f, "address is already in use")
			}

			Self::AddrNotAvailable => {
				write!(f, "address is not available")
			}

			Self::AlreadyExists => {
				write!(f, "path already exists")
			}

			Self::ArgumentListTooLong => {
				write!(f, "argument list is too long")
			}

			Self::BrokenPipe => {
				write!(f, "pipe is broken")
			}

			Self::ConnectionAborted => {
				write!(f, "connection has been aborted")
			}

			Self::ConnectionRefused => {
				write!(f, "connection has been refused")
			}

			Self::ConnectionReset => {
				write!(f, "connection has been reset")
			}

			Self::CrossesDevices => {
				write!(f, "cross-device link")
			}

			Self::Deadlock => {
				write!(f, "deadlock")
			}

			Self::DirectoryNotEmpty => {
				write!(f, "directory is not empty")
			}

			Self::ExecutableFileBusy => {
				write!(f, "executable file is busy")
			}

			Self::FileTooLarge => {
				write!(f, "file is too large")
			}

			Self::HostUnreachable => {
				write!(f, "host is unreachable")
			}

			Self::Interrupted => {
				write!(f, "operation was interrupted")
			}

			Self::InvalidData => {
				write!(f, "invalid data")
			}

			Self::InvalidFilename => {
				write!(f, "invalid file name")
			}

			Self::InvalidInput => {
				write!(f, "invalid input")
			}

			Self::IsADirectory => {
				write!(f, "path is a directory")
			}

			Self::NetworkDown => {
				write!(f, "network is down")
			}

			Self::NetworkUnreachable => {
				write!(f, "network is unreachable")
			}

			Self::NotADirectory => {
				write!(f, "path is not a directory")
			}

			Self::NotConnected => {
				write!(f, "connection is missing")
			}

			Self::NotFound => {
				write!(f, "path was not found")
			}

			Self::NotSeekable => {
				write!(f, "file is unseekable")
			}

			Self::Other => {
				write!(f, "unknown error")
			}

			Self::OutOfMemory => {
				write!(f, "out of memory")
			}

			Self::PermissionDenied => {
				write!(f, "permission was denied")
			}

			Self::QuotaExceeded => {
				write!(f, "quota has been exceeded")
			}

			Self::ReadOnlyFilesystem => {
				write!(f, "file system is read-only")
			}

			Self::ResourceBusy => {
				write!(f, "resource is busy")
			}

			Self::StaleNetworkFileHandle=> {
				write!(f, "network file handle is stale")
			}

			Self::StorageFull => {
				write!(f, "storage is full")
			}

			Self::TimedOut => {
				write!(f, "time out")
			}

			Self::TooManyLinks => {
				write!(f, "too many links")
			}

			Self::UnexpectedEof => {
				write!(f, "unexpected end of file")
			}

			Self::Unsupported => {
				write!(f, "unsupported operation")
			}

			Self::WouldBlock => {
				write!(f, "operation would block")
			}

			Self::WriteZero => {
				write!(f, "zero write")
			}

		}
	}
}

#[cfg(feature = "std")]
impl From<std::io::ErrorKind> for ErrorKind {
	#[inline]
	fn from(value: std::io::ErrorKind) -> Self {
		match value {
			std::io::ErrorKind::AddrInUse              => Self::AddrInUse,
			std::io::ErrorKind::AddrNotAvailable       => Self::AddrNotAvailable,
			std::io::ErrorKind::AlreadyExists          => Self::AlreadyExists,
			std::io::ErrorKind::ArgumentListTooLong    => Self::ArgumentListTooLong,
			std::io::ErrorKind::BrokenPipe             => Self::BrokenPipe,
			std::io::ErrorKind::ConnectionAborted      => Self::ConnectionAborted,
			std::io::ErrorKind::ConnectionRefused      => Self::ConnectionRefused,
			std::io::ErrorKind::ConnectionReset        => Self::ConnectionReset,
			std::io::ErrorKind::CrossesDevices         => Self::CrossesDevices,
			std::io::ErrorKind::Deadlock               => Self::Deadlock,
			std::io::ErrorKind::DirectoryNotEmpty      => Self::DirectoryNotEmpty,
			std::io::ErrorKind::ExecutableFileBusy     => Self::ExecutableFileBusy,
			std::io::ErrorKind::FileTooLarge           => Self::FileTooLarge,
			std::io::ErrorKind::HostUnreachable        => Self::HostUnreachable,
			std::io::ErrorKind::Interrupted            => Self::Interrupted,
			std::io::ErrorKind::InvalidData            => Self::InvalidData,
			std::io::ErrorKind::InvalidFilename        => Self::InvalidFilename,
			std::io::ErrorKind::InvalidInput           => Self::InvalidInput,
			std::io::ErrorKind::IsADirectory           => Self::IsADirectory,
			std::io::ErrorKind::NetworkDown            => Self::NetworkDown,
			std::io::ErrorKind::NetworkUnreachable     => Self::NetworkUnreachable,
			std::io::ErrorKind::NotADirectory          => Self::NotADirectory,
			std::io::ErrorKind::NotConnected           => Self::NotConnected,
			std::io::ErrorKind::NotFound               => Self::NotFound,
			std::io::ErrorKind::NotSeekable            => Self::NotSeekable,
			std::io::ErrorKind::OutOfMemory            => Self::OutOfMemory,
			std::io::ErrorKind::PermissionDenied       => Self::PermissionDenied,
			std::io::ErrorKind::QuotaExceeded          => Self::QuotaExceeded,
			std::io::ErrorKind::ReadOnlyFilesystem     => Self::ReadOnlyFilesystem,
			std::io::ErrorKind::ResourceBusy           => Self::ResourceBusy,
			std::io::ErrorKind::StaleNetworkFileHandle => Self::StaleNetworkFileHandle,
			std::io::ErrorKind::StorageFull            => Self::StorageFull,
			std::io::ErrorKind::TimedOut               => Self::TimedOut,
			std::io::ErrorKind::TooManyLinks           => Self::TooManyLinks,
			std::io::ErrorKind::UnexpectedEof          => Self::UnexpectedEof,
			std::io::ErrorKind::Unsupported            => Self::Unsupported,
			std::io::ErrorKind::WouldBlock             => Self::WouldBlock,
			std::io::ErrorKind::WriteZero              => Self::WriteZero,

			| std::io::ErrorKind::Other
			| _
			=> Self::Other,
		}
	}
}

#[cfg(feature = "std")]
impl From<ErrorKind> for std::io::ErrorKind {
	#[inline]
	fn from(value: ErrorKind) -> Self {
		match value {
			ErrorKind::AddrInUse              => Self::AddrInUse,
			ErrorKind::AddrNotAvailable       => Self::AddrNotAvailable,
			ErrorKind::AlreadyExists          => Self::AlreadyExists,
			ErrorKind::ArgumentListTooLong    => Self::ArgumentListTooLong,
			ErrorKind::BrokenPipe             => Self::BrokenPipe,
			ErrorKind::ConnectionAborted      => Self::ConnectionAborted,
			ErrorKind::ConnectionRefused      => Self::ConnectionRefused,
			ErrorKind::ConnectionReset        => Self::ConnectionReset,
			ErrorKind::CrossesDevices         => Self::CrossesDevices,
			ErrorKind::Deadlock               => Self::Deadlock,
			ErrorKind::DirectoryNotEmpty      => Self::DirectoryNotEmpty,
			ErrorKind::ExecutableFileBusy     => Self::ExecutableFileBusy,
			ErrorKind::FileTooLarge           => Self::FileTooLarge,
			ErrorKind::HostUnreachable        => Self::HostUnreachable,
			ErrorKind::Interrupted            => Self::Interrupted,
			ErrorKind::InvalidData            => Self::InvalidData,
			ErrorKind::InvalidFilename        => Self::InvalidFilename,
			ErrorKind::InvalidInput           => Self::InvalidInput,
			ErrorKind::IsADirectory           => Self::IsADirectory,
			ErrorKind::NetworkDown            => Self::NetworkDown,
			ErrorKind::NetworkUnreachable     => Self::NetworkUnreachable,
			ErrorKind::NotADirectory          => Self::NotADirectory,
			ErrorKind::NotConnected           => Self::NotConnected,
			ErrorKind::NotFound               => Self::NotFound,
			ErrorKind::NotSeekable            => Self::NotSeekable,
			ErrorKind::Other                  => Self::Other,
			ErrorKind::OutOfMemory            => Self::OutOfMemory,
			ErrorKind::PermissionDenied       => Self::PermissionDenied,
			ErrorKind::QuotaExceeded          => Self::QuotaExceeded,
			ErrorKind::ReadOnlyFilesystem     => Self::ReadOnlyFilesystem,
			ErrorKind::ResourceBusy           => Self::ResourceBusy,
			ErrorKind::StaleNetworkFileHandle => Self::StaleNetworkFileHandle,
			ErrorKind::StorageFull            => Self::StorageFull,
			ErrorKind::TimedOut               => Self::TimedOut,
			ErrorKind::TooManyLinks           => Self::TooManyLinks,
			ErrorKind::UnexpectedEof          => Self::UnexpectedEof,
			ErrorKind::Unsupported            => Self::Unsupported,
			ErrorKind::WouldBlock             => Self::WouldBlock,
			ErrorKind::WriteZero              => Self::WriteZero,
		}
	}
}