Debian Codegraph @

src/lib.rs

raw symbols SCIP
1 #![cfg_attr(test, deny(warnings))]
2 #![deny(missing_docs)]
3 #![cfg_attr(not(feature = "std"), no_std)]
4
5 //! # Void
6 //!
7 //! The uninhabited void type for use in statically impossible cases.
8 //!
9 //! In its own crate so all the users in the ecosystem can share the same type.
10 //! This crate also comes ready with several extension traits for Result that add
11 //! extra functionality to `Result<T, Void>` and `Result<Void, E>`.
12 //!
13
14 #[cfg(not(feature = "std"))]
15 mod coreproviderrust-analyzer cargo void 1.0.2 coreprovider/ {
16 extern crate core;
17 pub use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::{fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/, cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/};
18 }
19
20 #[cfg(feature = "std")]
21 mod coreproviderrust-analyzer cargo void 1.0.2 coreprovider/ {
22 pub use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/, cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/, errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/};
23 }
24
25 use coreproviderrust-analyzer cargo void 1.0.2 coreprovider/::*;
26
27 /// The empty type for cases which can't occur.
28 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:)]
29 pub enum Voidrust-analyzer cargo void 1.0.2 Void# { }
30
31 impl Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# for Voidrust-analyzer cargo void 1.0.2 Void# {
32 fn clonerust-analyzer cargo void 1.0.2 impl#[Void][Clone]clone().(&self) -> Voidrust-analyzer cargo void 1.0.2 Void# {
33 unreachablerust-analyzer cargo void 1.0.2 unreachable().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self)
34 }
35 }
36
37 impl fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for Voidrust-analyzer cargo void 1.0.2 Void# {
38 fn fmtrust-analyzer cargo void 1.0.2 impl#[Void][Debug]fmt().(&self, _: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
39 unreachablerust-analyzer cargo void 1.0.2 unreachable().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self)
40 }
41 }
42
43 impl fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for Voidrust-analyzer cargo void 1.0.2 Void# {
44 fn fmtrust-analyzer cargo void 1.0.2 impl#[Void][Display]fmt().(&self, _: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
45 unreachablerust-analyzer cargo void 1.0.2 unreachable().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self)
46 }
47 }
48
49 impl<T> cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<T> for Voidrust-analyzer cargo void 1.0.2 Void# {
50 fn eqrust-analyzer cargo void 1.0.2 impl#[Void][`PartialEq<T>`]eq().(&self, _: &T) -> bool {
51 unreachablerust-analyzer cargo void 1.0.2 unreachable().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self)
52 }
53 }
54
55 impl<T> cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#<T> for Voidrust-analyzer cargo void 1.0.2 Void# {
56 fn partial_cmprust-analyzer cargo void 1.0.2 impl#[Void][`PartialOrd<T>`]partial_cmp().(&self, _: &T) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#> {
57 unreachablerust-analyzer cargo void 1.0.2 unreachable().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self)
58 }
59 }
60
61 #[cfg(feature = "std")]
62 impl errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# for Voidrust-analyzer cargo void 1.0.2 Void# {
63 fn descriptionrust-analyzer cargo void 1.0.2 impl#[Void][Error]description().(&self) -> &str {
64 unreachablerust-analyzer cargo void 1.0.2 unreachable().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self)
65 }
66
67 fn causerust-analyzer cargo void 1.0.2 impl#[Void][Error]cause().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#> {
68 unreachablerust-analyzer cargo void 1.0.2 unreachable().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self)
69 }
70 }
71
72 /// A safe version of `intrinsincs::unreachable`.
73 ///
74 /// If this typechecks, anything that causes this to run is unreachable code.
75 ///
76 /// Calling this function in reachable code invokes undefined behavior, but
77 /// should not be possible unless `unsafe` was used elsewhere to construct
78 /// an instance of `Void` (which is already undefined behavior).
79 #[inline(always)]
80 pub fn unreachablerust-analyzer cargo void 1.0.2 unreachable().(x: Voidrust-analyzer cargo void 1.0.2 Void#) -> ! {
81 match x {}
82 }
83
84 /// Extensions to `Result<T, Void>`
85 pub trait ResultVoidExtrust-analyzer cargo void 1.0.2 ResultVoidExt#<T>: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# {
86 /// Get the value out of a wrapper.
87 fn void_unwraprust-analyzer cargo void 1.0.2 ResultVoidExt#void_unwrap().(self) -> T;
88 }
89
90 impl<T> ResultVoidExtrust-analyzer cargo void 1.0.2 ResultVoidExt#<T> for Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, Voidrust-analyzer cargo void 1.0.2 Void#> {
91 /// Get the value out of an always-ok Result.
92 ///
93 /// Never panics, since it is statically known to be Ok.
94 #[inline]
95 fn void_unwraprust-analyzer cargo void 1.0.2 impl#[`Result<T, Void>`][`ResultVoidExt<T>`]void_unwrap().(self) -> T {
96 match self {
97 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(val) => val,
98 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => unreachablerust-analyzer cargo void 1.0.2 unreachable().(e)
99 }
100 }
101 }
102
103 /// Extensions to `Result<Void, E>`
104 pub trait ResultVoidErrExtrust-analyzer cargo void 1.0.2 ResultVoidErrExt#<E>: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# {
105 /// Get the error out of a wrapper.
106 fn void_unwrap_errrust-analyzer cargo void 1.0.2 ResultVoidErrExt#void_unwrap_err().(self) -> E;
107 }
108
109 impl<E> ResultVoidErrExtrust-analyzer cargo void 1.0.2 ResultVoidErrExt#<E> for Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Voidrust-analyzer cargo void 1.0.2 Void#, E> {
110 /// Get the error out of an always-err Result.
111 ///
112 /// Never panics, since it is statically known to be Err.
113 #[inline]
114 fn void_unwrap_errrust-analyzer cargo void 1.0.2 impl#[`Result<Void, E>`][`ResultVoidErrExt<E>`]void_unwrap_err().(self) -> E {
115 match self {
116 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(v) => unreachablerust-analyzer cargo void 1.0.2 unreachable().(v),
117 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => e
118 }
119 }
120 }
121