ref_eq/lib.rs
1// Copyright 2012-2016 The Rust Project Developers. See the COPYRIGHT
2// at http://rust-lang.org/COPYRIGHT.
3//
4// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7// option. This file may not be copied, modified, or distributed
8// except according to those terms.
9
10//! The `req_eq` crate makes it easy to check reference equality.
11//!
12//! # Examples
13//!
14//! ```
15//! use ref_eq::ref_eq;
16//!
17//! let x = 1;
18//! let y = 1;
19
20//! assert!(ref_eq(&x, &x));
21//! assert!(!ref_eq(&x, &y));
22//! ```
23
24/// Determine if two borrowed pointers point to the same thing.
25#[inline]
26pub fn ref_eq<'a, 'b, T>(thing: &'a T, other: &'b T) -> bool {
27 (thing as *const T) == (other as *const T)
28}