[rust-dev] Static initialisation of LinearMap

Patrick Walton pwalton at mozilla.com
Tue Jul 2 09:15:21 PDT 2013


On 7/2/13 8:45 AM, Michael Neumann wrote:
> Am 02.07.2013 17:29, schrieb Alex Crichton:
>>> I was looking for something like: static h:HashMap<K,C> =
>>> {(K,V),(K,V).....}.
>>> Is this possible at all?
>
> What would be much easier is to use a sorted array and binary search for
> lookup.
> But sorting at compile time seams to be tricky, for simple values ok,
> but for more
> complex keys I think it's impossible.

A procedural macro (what we call a syntax extension) could do it. I've 
been thinking for a while that we should have such a syntax extension in 
the compiler. This is needed in Servo for "pre-interned identifiers": 
think well-known DOM attributes like "id" or HTML elements like "img".

Patrick



More information about the Rust-dev mailing list