Giter Club home page Giter Club logo

Comments (3)

woshilapin avatar woshilapin commented on May 23, 2024

I experimented this implementation but here are the problems.

If the new method is changed to

pub fn new(v: I) -> Result<Self>
where
	I: IntoIterator<Item = T>;

Then the implementation will call .into_iter() then .collect() to collect as a Vec. If the input parameter is already a Vec, this is an aberration to iterate over it in order to collect it again as a Vec.

Another solution would be to provide a From<IntoIterator<Item = T>> implementation. But this one causes also a problem. Below is a possible implementation.

impl<T: Id<T>, I: IntoIterator<Item = T>> From<I> for CollectionWithId<T> {
    fn from(iterator: I) -> Self {
        // This cannot fail since there will be a unique identifier in the
        // collection hence no identifier's collision.
        CollectionWithId::new(iterator.into_iter().collect()).unwrap()
    }
}

But it does not compile since it creates a conflicting implementation.

error[E0119]: conflicting implementations of trait `std::convert::From<collection::CollectionWithId<_>>` for type `collection::CollectionWithId<_>`:
   --> collection/src/collection.rs:405:1
    |
405 | impl<T: Id<T>, I: IntoIterator<Item = T>> From<I> for CollectionWithId<T> {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: conflicting implementation in crate `core`:
            - impl<T> std::convert::From<T> for T;

error: aborting due to previous error

Anyone has some ideas about that?

from transit_model.

woshilapin avatar woshilapin commented on May 23, 2024

Note that there is a FromIterator trait that could be implemented but this option has already been explored and rejected in #291.

from transit_model.

woshilapin avatar woshilapin commented on May 23, 2024

Therefore, let's close this issue (especially since this functionality has moved to its own repository now hove-io/typed_index_collections).

from transit_model.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.