blob: 567948287f3e53778cbe941de1c40ddee87aa32b [file] [log] [blame]
// Part of the Crubit project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//! Copyable, equality-comparable types for Salsa.
//!
//! TODO(jeanpierreda): give this module a better name.
use std::ops::Deref;
use std::rc::Rc;
/// A wrapper for a smart pointer, which implements `Eq` as pointer equality.
///
/// This was directly inspired by Chalk's `ArcEq`, which does the same.
#[derive(Clone, Debug, Default)]
#[repr(transparent)]
pub struct RcEq<T>(pub Rc<T>);
impl<T> PartialEq<RcEq<T>> for RcEq<T> {
fn eq(&self, other: &Self) -> bool {
std::ptr::eq(&*self.0, &*other.0)
}
}
impl<T> Eq for RcEq<T> {}
impl<T> Deref for RcEq<T> {
type Target = T;
fn deref(&self) -> &T {
&*self.0
}
}
impl<T> From<T> for RcEq<T> {
fn from(x: T) -> Self {
RcEq::new(x)
}
}
impl<T> RcEq<T> {
pub fn new(x: T) -> Self {
RcEq(Rc::new(x))
}
}