Skip to content

Commit 277b487

Browse files
committed
added feature to alias void to infallible
1 parent a6e0612 commit 277b487

File tree

3 files changed

+47
-44
lines changed

3 files changed

+47
-44
lines changed

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@ language: rust
22
sudo: false
33

44
rust:
5-
- 1.0.0
5+
- 1.34.0
66
- stable
77
- beta
88
- nightly
99

1010
script:
1111
- cargo build
1212
- cargo test
13-
- if [ "$TRAVIS_RUST_VERSION" != "1.0.0" ]; then cargo test --no-default-features; fi
13+
- cargo test --no-default-features
14+
- cargo test --features=infallible
15+
- cargo test --no-default-features --features=infallible
1416
- cargo bench --no-run
1517
- cargo doc
1618

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ repository = "https://github.com/reem/rust-void.git"
77
description = "The uninhabited void type for use in statically impossible cases."
88
readme = "README.md"
99
license = "MIT / Apache-2.0"
10+
edition = "2018"
1011

1112
[features]
13+
std = []
14+
infallible = []
1215

1316
default = ["std"]
14-
std = []
1517

src/lib.rs

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,62 +10,61 @@
1010
//! This crate also comes ready with several extension traits for Result that add
1111
//! extra functionality to `Result<T, Void>` and `Result<Void, E>`.
1212
//!
13+
//! This can be aliased to core::convert::Infallible using the crates `infallible` feature.
14+
//!
1315
14-
#[cfg(not(feature = "std"))]
15-
mod coreprovider {
16-
extern crate core;
17-
pub use core::{fmt, cmp};
18-
}
16+
/// The empty type for cases which can't occur (aliased to core::convert::Infallible)
17+
#[cfg(feature = "infallible")]
18+
pub type Void = core::convert::Infallible;
1919

20-
#[cfg(feature = "std")]
21-
mod coreprovider {
22-
pub use std::{fmt, cmp, error};
23-
}
20+
#[cfg(not(feature = "infallible"))]
21+
pub use void::Void;
2422

25-
use coreprovider::*;
23+
#[cfg(not(feature = "infallible"))]
24+
mod void {
25+
/// The empty type for cases which can't occur.
26+
#[derive(Copy)]
27+
pub enum Void { }
2628

27-
/// The empty type for cases which can't occur.
28-
#[derive(Copy)]
29-
pub enum Void { }
30-
31-
impl Clone for Void {
32-
fn clone(&self) -> Void {
33-
unreachable(*self)
29+
impl Clone for Void {
30+
fn clone(&self) -> Void {
31+
super::unreachable(*self)
32+
}
3433
}
35-
}
3634

37-
impl fmt::Debug for Void {
38-
fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
39-
unreachable(*self)
35+
impl core::fmt::Debug for Void {
36+
fn fmt(&self, _: &mut core::fmt::Formatter) -> core::fmt::Result {
37+
super::unreachable(*self)
38+
}
4039
}
41-
}
4240

43-
impl fmt::Display for Void {
44-
fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
45-
unreachable(*self)
41+
impl core::fmt::Display for Void {
42+
fn fmt(&self, _: &mut core::fmt::Formatter) -> core::fmt::Result {
43+
super::unreachable(*self)
44+
}
4645
}
47-
}
4846

49-
impl<T> cmp::PartialEq<T> for Void {
50-
fn eq(&self, _: &T) -> bool {
51-
unreachable(*self)
47+
impl<T> core::cmp::PartialEq<T> for Void {
48+
fn eq(&self, _: &T) -> bool {
49+
super::unreachable(*self)
50+
}
5251
}
53-
}
5452

55-
impl<T> cmp::PartialOrd<T> for Void {
56-
fn partial_cmp(&self, _: &T) -> Option<cmp::Ordering> {
57-
unreachable(*self)
53+
impl<T> core::cmp::PartialOrd<T> for Void {
54+
fn partial_cmp(&self, _: &T) -> Option<core::cmp::Ordering> {
55+
super::unreachable(*self)
56+
}
5857
}
59-
}
6058

61-
#[cfg(feature = "std")]
62-
impl error::Error for Void {
63-
fn description(&self) -> &str {
64-
unreachable(*self)
65-
}
59+
#[cfg(feature = "std")]
60+
impl std::error::Error for Void {
61+
fn description(&self) -> &str {
62+
super::unreachable(*self)
63+
}
6664

67-
fn cause(&self) -> Option<&error::Error> {
68-
unreachable(*self)
65+
fn cause(&self) -> Option<&(dyn std::error::Error)> {
66+
super::unreachable(*self)
67+
}
6968
}
7069
}
7170

0 commit comments

Comments
 (0)