pointer_identity/lib.rs
1//! # Pointer Identity
2//!
3//! Rust has some traits that operate on values:
4//!
5//! - [`Ord`] and [`PartialOrd`] check the ordering of values,
6//! - [`Eq`] and [`PartialEq`] check equality of values,
7//! - [`Hash`] computes a hash sum of values.
8//!
9//! When using smart pointers such as [`Arc`](std::sync::Arc), [`Rc`](std::rc::Rc) and [`Box`] in
10//! Rust, these will forward the implementation to the underlying types. Generally speaking, this
11//! makes sense and is the intended behavior.
12//!
13//! However, in some cases this might not be what you need. For example, in some cases where you
14//! have a cache of reference-counted values, you may want it to determine if two values are the
15//! same just by looking at their pointer address rather than inspecting the value.
16//!
17//! This crate lets you achieve that by offering a wrapper type, [`PointerIdentity`], that you can
18//! use to wrap any value which implements [`Pointer`] to get it to use the pointer address as
19//! identity for comparisons and hashing rather than the value of the data it is holding.
20
21mod identity;
22mod pointer;
23
24pub use crate::{identity::PointerIdentity, pointer::Pointer};