Skip to content

Commit

Permalink
consistently name <K, R> everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
mightyiam committed May 2, 2022
1 parent 3597812 commit cedaba8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion macro/src/lib.rs
Expand Up @@ -119,7 +119,7 @@ fn expand_fn_block(original_fn_block: Block, return_type: Type, attr_args: AttrA
.entry(type_id)
.or_insert_with(|| {
let store: #store_type = #store_init;
fn inference_hint<K, V, S: ::michie::MemoizationStore<K, V>>(k: &K, s: &S) {}
fn inference_hint<K, R, S: ::michie::MemoizationStore<K, R>>(k: &K, s: &S) {}
inference_hint(#key_ref, &store);
::std::boxed::Box::new(store)
});
Expand Down
18 changes: 9 additions & 9 deletions src/lib.rs
Expand Up @@ -8,31 +8,31 @@ use std::{
/// See [crate level documentation](crate).
pub use michie_macro::memoized;

pub trait MemoizationStore<K, V> {
fn insert(&mut self, key: K, value: V);
fn get(&self, key: &K) -> Option<&V>;
pub trait MemoizationStore<K, R> {
fn insert(&mut self, key: K, value: R);
fn get(&self, key: &K) -> Option<&R>;
}

impl<K, V> MemoizationStore<K, V> for HashMap<K, V>
impl<K, R> MemoizationStore<K, R> for HashMap<K, R>
where
K: Eq + Hash,
{
fn insert(&mut self, key: K, value: V) {
fn insert(&mut self, key: K, value: R) {
HashMap::insert(self, key, value);
}
fn get(&self, key: &K) -> Option<&V> {
fn get(&self, key: &K) -> Option<&R> {
HashMap::get(self, key)
}
}

impl<K, V> MemoizationStore<K, V> for BTreeMap<K, V>
impl<K, R> MemoizationStore<K, R> for BTreeMap<K, R>
where
K: Ord,
{
fn insert(&mut self, key: K, value: V) {
fn insert(&mut self, key: K, value: R) {
BTreeMap::insert(self, key, value);
}
fn get(&self, key: &K) -> Option<&V> {
fn get(&self, key: &K) -> Option<&R> {
BTreeMap::get(self, key)
}
}
14 changes: 7 additions & 7 deletions tests/test.rs
Expand Up @@ -129,21 +129,21 @@ fn store_init_is_used_instead_of_implementation_of_the_default_trait() {

#[test]
fn store_init_includes_a_concrete_store_type() {
struct Store<K, V> {
struct Store<K, R> {
k: PhantomData<K>,
v: PhantomData<V>,
r: PhantomData<R>,
}
impl<K, V> Store<K, V> {
impl<K, R> Store<K, R> {
fn new() -> Self {
Self {
k: PhantomData,
v: PhantomData,
r: PhantomData,
}
}
}
impl<K, V> MemoizationStore<K, V> for Store<K, V> {
fn insert(&mut self, _key: K, _value: V) {}
fn get(&self, _key: &K) -> Option<&V> {
impl<K, R> MemoizationStore<K, R> for Store<K, R> {
fn insert(&mut self, _key: K, _value: R) {}
fn get(&self, _key: &K) -> Option<&R> {
None
}
}
Expand Down

0 comments on commit cedaba8

Please sign in to comment.