Giter Site home page Giter Site logo

Comments (3)

kennytm avatar kennytm commented on August 20, 2024 1

You don't need dynamic dispatch.

#![feature(specialization)]

trait Lookup: Sized {
    type Collection: Collection<Self>;
}

impl<T> Lookup for T {
    default type Collection = Vec<T>;
}

impl<T: Hash> Lookup for T {
    type Collection = HashSet<T>;
}

struct Wrapper<T: Lookup> {
    information: T::Collection,
}

from rfcs.

Pscheidl avatar Pscheidl commented on August 20, 2024

True, thank you. Doable once (if) Impl specialization arives then. It is quite verbose, but I can see the advantage of that. On the other hand, the approach ^ could be treated as a syntactic sugar ?

from rfcs.

kennytm avatar kennytm commented on August 20, 2024

the approach ^ could be treated as a syntactic sugar ?

At least the syntax proposed in OP is impossible, since without a concrete T you don't know the exact type of self.information and thus can't call any useful method. You still need that Collection trait and with that struct specialization syntax you can't associate the trait Collection to the member information anywhere.

from rfcs.

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.