If the traits were polymorphic in the index type (instead of always
expecting an integer), then one could use them to make hash tables use
vector syntax (e.g., `hash["foo"] = 1`)... Ruby does that, for example. So
something like bitset (with integer indices) isn't the only example.

Not sure whether we want to go that way, though...


On Fri, Nov 15, 2013 at 3:35 PM, Diggory Hardy <li...@dhardy.name> wrote:

> In reply to Nicholas Matsakis's post:
>
> http://smallcultfollowing.com/babysteps/blog/2013/11/14/treating-vectors-like-any-other-container/
>
> That's a really nice write-up Nicholas. I wanted to chip in because I had a
> think about some similar issues in the past, but your review is far more
> thorough and knowledgeable than I could have managed.
>
> Regarding Gc<[uint]> (or @[T]), this seems fairly useless to me, given that
> @mut[T] would not be memory safe (unless it is @mut ~[T] or reallocating
> the
> buffer is not allowed), thus the only way of constructing @[T] would be to
> coerce a ~[T] or a literal.
>
> For me, the biggest plus of your proposal is uniformity: e.g. someone could
> implement something like C++'s std::bitset and have it look syntactically
> equivalent to Vector<T> (although given that std::bitset is not very useful
> and Boost's "Pointer Containers" are redundant in both C++11 and Rust, I'm
> struggling to find an example where this is actually needed). Given the
> three
> big drawbacks (implementation effort, syntax and pattern matching) it may
> not
> be worth it.
>
> Using a builder trait to construct user-defined objects from literals is a
> nice
> approach (I believe it could also be useful in type-safe printf-like
> formatters and embedded DSLs for things like constructing HTML or parser
> rules), but some things like method lookup won't always be possible:
>
> let v : Vector<int> = [1,2,3].append_one( 4 )
> _______________________________________________
> Rust-dev mailing list
> Rust-dev@mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev
>
>
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to