diff --git a/src/unify/mod.rs b/src/unify/mod.rs index a26d699..42bda79 100644 --- a/src/unify/mod.rs +++ b/src/unify/mod.rs @@ -24,13 +24,14 @@ //! When you have keys with non-trivial values, you must also define //! how those values can be merged. As part of doing this, you can //! define the "error" type to return on error; if errors are not -//! possible, use `NoError` (an uninstantiable struct). Using this -//! type also unlocks various more ergonomic methods (e.g., `union()` -//! in place of `unify_var_var()`). +//! possible, use [`Infallible`](core::convert::Infallible) +//! an uninstantiable enum). Using this type also unlocks various more +//! ergonomic methods (e.g., `union()` in place of `unify_var_var()`). //! //! The best way to see how it is used is to read the `tests.rs` file; //! search for e.g. `UnitKey`. +use std::convert::Infallible; use std::fmt::Debug; use std::marker; use std::ops::Range; @@ -109,8 +110,8 @@ pub trait UnifyKey: Copy + Clone + Debug + PartialEq { /// equal. pub trait UnifyValue: Clone + Debug { /// Defines the type to return when merging of two values fails. - /// If merging is infallible, use the special struct `NoError` - /// found in this crate, which unlocks various more convenient + /// If merging is infallible, use the special struct [`Infallible`] + /// which unlocks various more convenient /// methods on the unification table. type Error; @@ -144,13 +145,6 @@ impl UnifyValue for T { } } -/// A struct which can never be instantiated. Used -/// for the error type for infallible cases. -#[derive(Debug)] -pub struct NoError { - _dummy: (), -} - /// Value of a unification key. We implement Tarjan's union-find /// algorithm: when two keys are unified, one of them is converted /// into a "redirect" pointing at the other. These redirects form a @@ -471,24 +465,24 @@ where V: UnifyValue, { /// Unions two keys without the possibility of failure; only - /// applicable when unify values use `NoError` as their error + /// applicable when unify values use [`Infallible`] as their error /// type. pub fn union(&mut self, a_id: K1, b_id: K2) where K1: Into, K2: Into, - V: UnifyValue, + V: UnifyValue, { self.unify_var_var(a_id, b_id).unwrap(); } /// Unions a key and a value without the possibility of failure; - /// only applicable when unify values use `NoError` as their error + /// only applicable when unify values use [`Infallible`] as their error /// type. pub fn union_value(&mut self, id: K1, value: V) where K1: Into, - V: UnifyValue, + V: UnifyValue, { self.unify_var_value(id, value).unwrap(); } @@ -571,9 +565,9 @@ where /////////////////////////////////////////////////////////////////////////// impl UnifyValue for () { - type Error = NoError; + type Error = Infallible; - fn unify_values(_: &(), _: &()) -> Result<(), NoError> { + fn unify_values(_: &(), _: &()) -> Result<(), Infallible> { Ok(()) } } diff --git a/src/unify/tests.rs b/src/unify/tests.rs index 5665aba..8cc2b9e 100644 --- a/src/unify/tests.rs +++ b/src/unify/tests.rs @@ -19,7 +19,7 @@ use self::test::Bencher; use std::cmp; #[cfg(feature = "persistent")] use unify::Persistent; -use unify::{EqUnifyValue, InPlace, InPlaceUnificationTable, NoError, UnifyKey, UnifyValue}; +use unify::{EqUnifyValue, InPlace, InPlaceUnificationTable, Infallible, UnifyKey, UnifyValue}; use unify::{UnificationStore, UnificationTable}; #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)] @@ -397,9 +397,9 @@ impl UnifyKey for OrderedKey { } impl UnifyValue for OrderedRank { - type Error = NoError; + type Error = Infallible; - fn unify_values(value1: &Self, value2: &Self) -> Result { + fn unify_values(value1: &Self, value2: &Self) -> Result { Ok(OrderedRank(cmp::max(value1.0, value2.0))) } }