chatora_errno/
lib.rs

1#![warn(
2    explicit_outlives_requirements,
3    invalid_html_tags,
4    macro_use_extern_crate,
5    missing_copy_implementations,
6    missing_crate_level_docs,
7    missing_debug_implementations,
8    missing_doc_code_examples,
9    missing_docs,
10    pointer_structural_match,
11    private_doc_tests,
12    single_use_lifetimes,
13    trivial_casts,
14    trivial_numeric_casts,
15    unreachable_pub,
16    // unsafe_op_in_unsafe_fn,
17    unused_crate_dependencies,
18    unused_extern_crates,
19    unused_import_braces,
20    unused_lifetimes,
21    unused_qualifications,
22    unused_results,
23    variant_size_differences,
24    clippy::pedantic,
25    clippy::nursery,
26    clippy::cargo,
27    clippy::clone_on_ref_ptr,
28    clippy::exhaustive_enums,
29    clippy::exhaustive_structs,
30    clippy::filetype_is_file,
31    clippy::float_cmp_const,
32    clippy::if_then_some_else_none,
33    clippy::lossy_float_literal,
34    clippy::rc_buffer,
35)]
36#![allow(
37    // clippy::cognitive_complexity,
38    clippy::missing_errors_doc,
39    clippy::multiple_crate_versions,
40    clippy::must_use_candidate,
41)]
42// #![rustfmt::skip]
43// #![clippy::cognitive_complexity_threshold = "20"]
44#![doc(test(no_crate_inject, attr(allow(unused_variables), deny(warnings))))]
45
46//! A thin Rust wrapper library around libc [`errno`][errno] interface.
47//!
48//! [errno]: https://en.wikipedia.org/wiki/Errno.h
49//!
50//!
51//! # Examples
52//!
53//! ```rust
54//! use chatora_errno::{clear_errno, describe_errno, get_errno, set_errno};
55//!
56//! // Clear current errno.
57//! clear_errno();
58//!
59//! // Get the current value of errno.
60//! let errno: i32 = get_errno();
61//!
62//! assert_eq!(errno, 0);
63//!
64//! // Equivalent to `clear_errno()`.
65//! set_errno(0);
66//!
67//! // Get string description of an errno.
68//! let err_string: String = describe_errno(errno).unwrap();
69//!
70//! assert_eq!(
71//!     format!("{} (os error {})", err_string, errno),
72//!     format!("{}", std::io::Error::from_raw_os_error(errno))
73//! );
74//! assert_eq!(err_string, "Success");
75//! ```
76
77#[cfg(doctest)]
78#[macro_use]
79extern crate doc_comment;
80#[cfg(doctest)]
81doctest!("../README.md");
82
83// Avoid `unused_crate_dependencies`.
84#[cfg(doctest)]
85use doc_comment as _;
86
87#[cfg(not(any(
88    target_os = "linux",
89    target_os = "emscripten",
90    target_os = "fuchsia",
91    target_os = "l4re",
92    target_os = "netbsd",
93    target_os = "openbsd",
94    target_os = "android",
95    target_os = "redox",
96    target_env = "newlib",
97    any(target_os = "solaris", target_os = "illumos"),
98    any(target_os = "macos", target_os = "ios", target_os = "freebsd"),
99    target_os = "haiku",
100    target_os = "wasi",
101)))]
102compile_error!("Unsupported `target_os`.");
103
104#[cfg_attr(target_family = "unix", path = "unix.rs")]
105#[cfg_attr(target_os = "wasi", path = "wasi.rs")]
106mod os;
107
108pub use self::os::{clear_errno, describe_errno, get_errno, set_errno};