fitzgen / scrapmetal

Scrap Your Rust Boilerplate
Apache License 2.0
54 stars 2 forks source link

Need help implementing `Term` for all `std` types #1

Open fitzgen opened 7 years ago

fitzgen commented 7 years ago

See a mostly complete list here: https://github.com/fitzgen/scrapmetal/blob/b77415238569174bebb50341aab29a7db105c64e/src/term_impls.rs#L121-L418

Lots of work to be done here, easy to parallelize across multiple PRs from multiple folks :)

JoeyEremondi commented 6 years ago

I'd definitely be interested in helping one of these, I'm currently using your library to implement substitutions over terms for some programming-languages work I'm doing. I'm also looking to get in some PRs for Hacktoberfest.

What would you think of something like this:

impl<C,T,I> Term for C where
  C : IntoIter<Item = T, IntoIter =I> + FromIterator<T>,
  T : Term,
  I : Iterator<Item = T> {...
  //Bodies implemented using iter functions
} 

This would knock a bunch of collections off the list.

fitzgen commented 6 years ago

Hi @JoeyEremondi !

My concern is that we may want to special case Term for some collection and that this blanket implementation would preclude that. We could definitely write a macro_rules for this, and then we would just have a tiny bit of copy-pasting (or we could go even deeper to avoid even this).

Something like:

macro_rules! impl_term_for_collection {
    (
        $(
            $collection:ty ;
        )*
    ) => {
        $(
            impl Term for $collection {
                // ...
            }
        )*
    }
}

// And then use it...
impl_term_for_collection! {
    Vec<T>;
    HashMap<K, V>
}

(The macro would need to handle type parameters and their bounds too, which my sketch doesn't do.)

What do you think of this approach?