Skip to content

Commit

Permalink
fix fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
puuuuh committed Oct 10, 2024
1 parent 01d7aab commit 3e8ae96
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
31 changes: 16 additions & 15 deletions src/interned.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
use std::fmt;
use std::hash::{BuildHasher, Hash, Hasher};
use std::marker::PhantomData;
use std::path::{Path, PathBuf};
use crate::durability::Durability;
use crate::id::AsId;
use crate::ingredient::fmt_index;
Expand All @@ -13,6 +9,10 @@ use crate::table::Slot;
use crate::zalsa::IngredientIndex;
use crate::zalsa_local::QueryOrigin;
use crate::{Database, DatabaseKeyIndex, Id};
use std::fmt;
use std::hash::{BuildHasher, Hash, Hasher};
use std::marker::PhantomData;
use std::path::{Path, PathBuf};

use super::hash::FxDashMap;
use super::ingredient::Ingredient;
Expand Down Expand Up @@ -308,7 +308,7 @@ where

/// The `Lookup` trait is a more flexible variant on [`std::borrow::Borrow`]
/// and [`std::borrow::ToOwned`]. It is implemented by "some type that can
/// be used as the lookup key for `O`". This means that `self`
/// be used as the lookup key for `O`". This means that `self`
/// can be hashed and compared for equality with values of type `O`
/// without actually creating an owned value. It `self` needs to be interned,
/// it can be converted into an equivalent value of type `O`.
Expand All @@ -319,16 +319,15 @@ where
/// where `struct ViewStruct<L1: Lookup<K1>...>(K1...)`. The `Borrow` trait
/// requires that `&(K1...)` be convertible to `&ViewStruct` which just isn't
/// possible. `Lookup` instead offers direct `hash` and `eq` methods.
pub trait Lookup<O>
{
pub trait Lookup<O> {
fn hash<H: Hasher>(&self, h: &mut H);
fn eq(&self, data: &O) -> bool;
fn into_owned(self) -> O;
}

impl<T> Lookup<T> for T
where
T: Hash + Eq
T: Hash + Eq,
{
fn hash<H: Hasher>(&self, h: &mut H) {
Hash::hash(self, &mut *h);
Expand Down Expand Up @@ -382,12 +381,13 @@ impl<A: Hash + Eq + PartialEq<T> + Clone + Lookup<T>, T> Lookup<Vec<T>> for &[A]
}

fn eq(&self, data: &Vec<T>) -> bool {
self.len() == data.len() &&
data.iter().enumerate().all(|(i, a)| &self[i] == a)
self.len() == data.len() && data.iter().enumerate().all(|(i, a)| &self[i] == a)
}

fn into_owned(self) -> Vec<T> {
self.into_iter().map(|a| Lookup::into_owned(a.clone())).collect()
self.into_iter()
.map(|a| Lookup::into_owned(a.clone()))
.collect()
}
}

Expand All @@ -399,12 +399,13 @@ impl<const N: usize, A: Hash + Eq + PartialEq<T> + Clone + Lookup<T>, T> Lookup<
}

fn eq(&self, data: &Vec<T>) -> bool {
self.len() == data.len() &&
data.iter().enumerate().all(|(i, a)| &self[i] == a)
self.len() == data.len() && data.iter().enumerate().all(|(i, a)| &self[i] == a)
}

fn into_owned(self) -> Vec<T> {
self.into_iter().map(|a| Lookup::into_owned(a.clone())).collect()
self.into_iter()
.map(|a| Lookup::into_owned(a.clone()))
.collect()
}
}

Expand All @@ -420,4 +421,4 @@ impl Lookup<PathBuf> for &Path {
fn into_owned(self) -> PathBuf {
self.to_owned()
}
}
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ pub mod plumbing {
pub use crate::interned::Configuration;
pub use crate::interned::IngredientImpl;
pub use crate::interned::JarImpl;
pub use crate::interned::Value;
pub use crate::interned::Lookup;
pub use crate::interned::Value;
}

pub mod function {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
//! Test that a `tracked` fn on a `salsa::input`
//! compiles and executes successfully.

use std::path::{Path, PathBuf};
use expect_test::expect;
use std::path::{Path, PathBuf};
use test_log::test;

#[salsa::interned]
struct InternedString<'db> {
data: String,
}


#[salsa::interned]
struct InternedPair<'db> {
data: (InternedString<'db>, InternedString<'db>),
Expand Down

0 comments on commit 3e8ae96

Please sign in to comment.