Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added infallible feature to alias void::Void to core::convert::Infallible #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ language: rust
sudo: false

rust:
- 1.0.0
- 1.34.0
- stable
- beta
- nightly

script:
- cargo build
- cargo test
- if [ "$TRAVIS_RUST_VERSION" != "1.0.0" ]; then cargo test --no-default-features; fi
- cargo test --no-default-features
- cargo test --features=infallible
- cargo test --no-default-features --features=infallible
- cargo bench --no-run
- cargo doc

Expand Down
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ repository = "https://github.com/reem/rust-void.git"
description = "The uninhabited void type for use in statically impossible cases."
readme = "README.md"
license = "MIT / Apache-2.0"
edition = "2018"

[features]
std = []
infallible = []

default = ["std"]
std = []

81 changes: 40 additions & 41 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,62 +10,61 @@
//! This crate also comes ready with several extension traits for Result that add
//! extra functionality to `Result<T, Void>` and `Result<Void, E>`.
//!
//! This can be aliased to core::convert::Infallible using the crates `infallible` feature.
//!

#[cfg(not(feature = "std"))]
mod coreprovider {
extern crate core;
pub use core::{fmt, cmp};
}
/// The empty type for cases which can't occur (aliased to core::convert::Infallible)
#[cfg(feature = "infallible")]
pub type Void = core::convert::Infallible;

#[cfg(feature = "std")]
mod coreprovider {
pub use std::{fmt, cmp, error};
}
#[cfg(not(feature = "infallible"))]
pub use void::Void;

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

/// The empty type for cases which can't occur.
#[derive(Copy)]
pub enum Void { }

impl Clone for Void {
fn clone(&self) -> Void {
unreachable(*self)
impl Clone for Void {
fn clone(&self) -> Void {
super::unreachable(*self)
}
}
}

impl fmt::Debug for Void {
fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
unreachable(*self)
impl core::fmt::Debug for Void {
fn fmt(&self, _: &mut core::fmt::Formatter) -> core::fmt::Result {
super::unreachable(*self)
}
}
}

impl fmt::Display for Void {
fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
unreachable(*self)
impl core::fmt::Display for Void {
fn fmt(&self, _: &mut core::fmt::Formatter) -> core::fmt::Result {
super::unreachable(*self)
}
}
}

impl<T> cmp::PartialEq<T> for Void {
fn eq(&self, _: &T) -> bool {
unreachable(*self)
impl<T> core::cmp::PartialEq<T> for Void {
fn eq(&self, _: &T) -> bool {
super::unreachable(*self)
}
}
}

impl<T> cmp::PartialOrd<T> for Void {
fn partial_cmp(&self, _: &T) -> Option<cmp::Ordering> {
unreachable(*self)
impl<T> core::cmp::PartialOrd<T> for Void {
fn partial_cmp(&self, _: &T) -> Option<core::cmp::Ordering> {
super::unreachable(*self)
}
}
}

#[cfg(feature = "std")]
impl error::Error for Void {
fn description(&self) -> &str {
unreachable(*self)
}
#[cfg(feature = "std")]
impl std::error::Error for Void {
fn description(&self) -> &str {
super::unreachable(*self)
}

fn cause(&self) -> Option<&error::Error> {
unreachable(*self)
fn cause(&self) -> Option<&(dyn std::error::Error)> {
super::unreachable(*self)
}
}
}

Expand Down