

Rust, Generics, and Collections - Gankro
http://cglab.ca/~abeinges/blah/rust-generics-and-collections/

======
kibwen
Ha, that trick with `Map<T, ()>` is actually really neat, and I'm happy to see
that there's no qualms about its efficiency that would preclude its use in the
standard library. This post has inadvertently become the most thorough
documentation on zero-sized types that I know of, in addition to being the
gold standard for guiding people interested in implementing data structures in
Rust. :)

~~~
Gankro
And I completely forgot about how they can be used to give collections
"chunks" of code to run without the need for function pointers!

And how you can use unboxed closures with no captures to make a zero-sized
bundle of static-data.

Ah well. More stuff for part-2.

------
avz
Interestingly, if we limit ourselves to pure functions, a ZST corresponds to
category-theoretic concept of the terminal object. The latter is defined as
such an object (think "type") T that for any other object (think "another
type") X there is precisely one arrow (think "function") from X to T [1].
Indeed, if T is a ZST like the empty tuple () then for any type of argument
there is precisely one function to T: namely, the one returning T's sole
value, ().

Also, Result<T, E> is an example of a variant type corresponding neatly to co-
products [2].

[1]
[http://en.wikipedia.org/wiki/Initial_and_terminal_objects](http://en.wikipedia.org/wiki/Initial_and_terminal_objects)

[2]
[http://en.wikipedia.org/wiki/Coproduct](http://en.wikipedia.org/wiki/Coproduct)

------
ludamad
It'd be nice if the examples had syntax highlighting.

~~~
Gankro
Done.

------
yazaddaruvala
Hey @Gankro, your blah/ dir doesn't have an index of all files. Unless you
know the links for these Rust posts, you can't really navigate to them.
Especially if you keep posting, which you should, I'd keep in mind the
navigation to and from these rust-lang posts.

~~~
Gankro
There is a blah/rss.xml, but yeah that's on my TODO. Maybe for the next post.

------
throwaway928
Why not use `fold` to implement `find_min`?

~~~
Gankro
Well I mean if you want to cheat with iterator adaptors you can just use
min_by: [http://doc.rust-
lang.org/std/iter/trait.IteratorExt.html#tym...](http://doc.rust-
lang.org/std/iter/trait.IteratorExt.html#tymethod.min_by)

:P

(shhh I was tired and trying to come up with a simple but moderate complexity
example)

