mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
Prefer plain trait definitions over macros for salsa
This commit is contained in:
parent
e059feadef
commit
3874681cb6
7 changed files with 37 additions and 33 deletions
|
@ -98,26 +98,27 @@ impl<A: InternValue + Eq + Hash + Debug + Clone, B: InternValue + Eq + Hash + De
|
|||
}
|
||||
}
|
||||
|
||||
/// Implement [`InternValue`] trivially, that is without actually mapping at all.
|
||||
#[macro_export]
|
||||
macro_rules! impl_intern_value_trivial {
|
||||
($($ty:ty),*) => {
|
||||
$(
|
||||
impl $crate::InternValue for $ty {
|
||||
type Key = $ty;
|
||||
#[inline]
|
||||
fn into_key(&self) -> Self::Key {
|
||||
self.clone()
|
||||
}
|
||||
#[inline]
|
||||
fn with_key<F: FnOnce(&Self::Key) -> T, T>(&self, f: F) -> T {
|
||||
f(self)
|
||||
}
|
||||
}
|
||||
)*
|
||||
};
|
||||
pub trait InternValueTrivial
|
||||
where
|
||||
Self: Eq + Hash + Debug + Clone,
|
||||
{
|
||||
}
|
||||
impl_intern_value_trivial!(String);
|
||||
|
||||
/// Implement [`InternValue`] trivially, that is without actually mapping at all.
|
||||
impl<V: InternValueTrivial> InternValue for V {
|
||||
type Key = Self;
|
||||
#[inline]
|
||||
fn into_key(&self) -> Self::Key {
|
||||
self.clone()
|
||||
}
|
||||
#[inline]
|
||||
fn with_key<F: FnOnce(&Self::Key) -> T, T>(&self, f: F) -> T {
|
||||
f(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl InternValueTrivial for String {}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Slot<V> {
|
||||
/// DatabaseKeyIndex for this slot.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue