Skip to content

More general Unifiable #11

@philippeitis

Description

@philippeitis

I'd like to be able to use Unifiable with AsRef<str> (or even more generally, AsRef<[u8]>) and IntoIterator types. The particular case where this comes up for me is in trying to provide a minimally allocating interface to Rust's string methods, such as splitn. The current interface either requires me to implement a copy of the Unifiable methods for slices (which is undesirable, and liable to break in future versions of this crate), or requires me to collect everything into a vector, which allocates for no good reason.

Ideally, such a change would allow something like this:

[1u64].unify(term);
std::iter::once("Hello world!").unify(term);
term.unify("hello world".splitn(5, " "));

I have a partially working copy of such a feature - however, the impl of Unifiable for Arc causes errors when implementing the methods for AsRef<[u8]> and IntoIterator - as seen below:

error[E0119]: conflicting implementations of trait `term::Unifiable` for type `std::sync::Arc<_>`
   --> swipl/src/term.rs:808:1
    |
808 | unsafe impl<S: AsRef<[u8]>> Unifiable for S {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `std::sync::Arc<_>`
    |
   ::: swipl/src/blob.rs:527:1
    |
527 | unsafe impl<T: ArcBlob> Unifiable for Arc<T> {
    | -------------------------------------------- first implementation here

error[E0119]: conflicting implementations of trait `term::Unifiable` for type `std::sync::Arc<_>`
   --> swipl/src/term.rs:916:1
    |
916 | / unsafe impl<'a, T, I> Unifiable for I
917 | | where
918 | |     T: Unifiable,
919 | |     I: IntoIterator<Item=T>,
...   |
964 | |     }
965 | | }
    | |_^ conflicting implementation for `std::sync::Arc<_>`
    |
   ::: swipl/src/blob.rs:527:1
    |
527 |   unsafe impl<T: ArcBlob> Unifiable for Arc<T> {
    |   -------------------------------------------- first implementation here
    |
    = note: upstream crates may add a new impl of trait `std::iter::Iterator` for type `std::sync::Arc<_>` in future versions
    = note: upstream crates may add a new impl of trait `std::iter::Iterator` for type `std::sync::Arc<_>` in future versions

Given that you'd obviously still want to support Unifiable for Arc<T>, I'm not sure what the best solution is here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions