[rust-dev] Syntax sugar: Vec Rc RefCell Box Foo -> Vec<Rc<RefCell<Box<Foo>>>>

Nathan Typanski ntypanski at gmail.com
Wed Jul 9 14:13:46 PDT 2014


I ran stats on the type parameters on Rust's master branch.

(I was dumb and only sent this to Ben Striegel last time. My fault for
not knowing how to use an email client.)

On 06/30, Benjamin Striegel wrote:
> Whether or not we want something like this, I'd be fascinated if someone
> managed to gather stats on how many types take only a single type parameter.

I had to do part of this by hand (thanks to false positives and it
being cumbersome to script for lifetime parameters) but I ran

    ag "pub.*struct.*<.*(?<!')\w>" > typed

in the rustc directory, did my best to weed out false positives, and
then counted by crate both the total and the number with only one
parameter.

So these numbers could be off by a bit - it's possible to write
structs that the regex above won't match, and it's possible that
somewhere I made a mistake counting things, but this should give a
nice rough idea.

- 160/191 (84%) parameterized structs in the "standard crates" take
only one type parameter.
    - 40/50 in libcore
    - 9/10 in librand
    - 5/5 in liballoc
    - 1/1 in debug
    - 5/5 in librustrt
    - 1/1 in libtest
    - 2/2 in libterm
    - 23/24 in libsync
    - 3/3 in libserialize
    - 19/28 in libstd
    - 8/8 in libsyntax
    - 27/34 in libcollections
    - 11/14 in librustc
    - 2/2 in libgreen
    - 1/1 in libnative
    - 1/1 in libarena
    - 2/2 in libnum

For traits:

- 52/74 (70%) of parameterized traits take one type parameter.
    - 23/37 in libcore
    - 1/1 in librustrt
    - 1/3 in libgraphviz
    - 4/4 in librand
    - 1/1 in libterm
    - 4/6 in libserialize
    - 11/13 in libcollections
    - 2/3 in librustc
    - 2/3 in libstd
    - 1/1 in librustdoc
    - 1/1 in librustuv
    - 1/1 in libsyntax

Nathan


More information about the Rust-dev mailing list