1# errno [![CI](https://github.com/lambda-fairy/rust-errno/actions/workflows/main.yml/badge.svg)](https://github.com/lambda-fairy/rust-errno/actions/workflows/main.yml) [![Cargo](https://img.shields.io/crates/v/errno.svg)](https://crates.io/crates/errno)
2
3Cross-platform interface to the [`errno`][errno] variable. Works on Rust 1.56 or newer.
4
5Documentation is available at <https://docs.rs/errno>.
6
7[errno]: https://en.wikipedia.org/wiki/Errno.h
8
9
10## Dependency
11
12Add to your `Cargo.toml`:
13
14```toml
15[dependencies]
16errno = "*"
17```
18
19
20## Comparison with `std::io::Error`
21
22The standard library provides [`Error::last_os_error`][last_os_error] which fetches `errno` in the same way.
23
24This crate provides these extra features:
25
26- No heap allocations
27- Optional `#![no_std]` support
28- A `set_errno` function
29
30[last_os_error]: https://doc.rust-lang.org/std/io/struct.Error.html#method.last_os_error
31
32
33## Examples
34
35```rust
36extern crate errno;
37use errno::{Errno, errno, set_errno};
38
39// Get the current value of errno
40let e = errno();
41
42// Set the current value of errno
43set_errno(e);
44
45// Extract the error code as an i32
46let code = e.0;
47
48// Display a human-friendly error message
49println!("Error {}: {}", code, e);
50```
51
52
53## `#![no_std]`
54
55Enable `#![no_std]` support by disabling the default `std` feature:
56
57```toml
58[dependencies]
59errno = { version = "*", default-features = false }
60```
61
62The `Error` impl will be unavailable.
63