Tuesday, January 14, 2020

Why no traits for collections in Rust?

I tried to write a generic function which converts a list to a receiver channel.
Originally I wrote this function taking Vec, but I wanted to change to Collection type which is sort of 'super' type of Vec, but there is no such type in Rust.

There are interesting research in this direction in Rust.


https://www.reddit.com/r/rust/comments/83q25s/why_no_traits_for_collections_in_rust/

Why no traits for collections in Rust?

In Java, there are interfaces such as Collection and Map that are used to identify generic collections--e.g. ArrayList and HashSet implement Collection, and HashMap and TreeMap implement Map.
I'd like having this capability in Rust as well, in case I'm designing a library and want the user to be able to decide which implementation of a collection they'd like to use. However, I noticed Rust doesn't have traits to represent a generic collection. I was wondering if this was an intentional design decision and what the reasoning was.


http://smallcultfollowing.com/babysteps/blog/2016/11/02/associated-type-constructors-part-1-basic-concepts-and-introduction/


https://github.com/rust-lang/rfcs/pull/1598

No comments:

Post a Comment

Recursive Matrix and the parallel matrix multiplication using crossbeam and generic constant

This was planned project I posted before. Basically in order to evaluate Rust's claim for zero cost abstraction and the effectiveness o...