Apparently include_bin!() returns a "binary" literal, not an actual slice. This
eventually gets treated as a &[u8] during type-checking, but it's apparently
treated specially by trans.
Given this, I think creating an include_sized_bin!() would require changing
LitBinary to include an optional size, and changing typeck to treat it as an
array instead of a slice when it has a size. Certainly doable, but not quite as
trivial as just defining a new syntax extension.
I also wonder if perhaps this would be better done as just a variant of
include_bin!(), e.g. `include_bin!("lut_stuff.bin", 1000)` or
`include_bin!("lut_stuff.bin", size=1000)`.
-Kevin
On May 27, 2014, at 10:11 AM, Tommi Tissari <[email protected]> wrote:
> I would use it for large, immutable, static lookup tables. I could use
> 'include_bin' and wrap any use of it in a 'std::mem::transmute', but I'd
> rather not. Also, I'd appreciate the sanity check for knowing the file size
> matches the size of the lookup table's type. E.g.
>
> static lut: [[MyStruct, ..1000], ..1000] = include_sized_bin!([[MyStruct,
> ..1000], ..1000], "lut_stuff.bin");
>
> I've tried initializing my large lookup table using the normal fixed size
> vector literal syntax, but it killed the compilation time and my computer ran
> out of memory.
>
>> On 27 May 2014, at 19:50, Kevin Ballard <[email protected]> wrote:
>>
>> What's the use-case for this?
>>
>> -Kevin
>>
>>> On May 27, 2014, at 3:24 AM, Tommi <[email protected]> wrote:
>>>
>>> Could we add to the standard library a macro, say 'include_sized_bin', that
>>> would be similar to std::macros::builtin::include_bin except that you'd
>>> also give it a sized type to return (instead of a slice of u8's) and you'd
>>> get a compile time error if the size of the file is different from the size
>>> of the type you specified.
>>>
>>> _______________________________________________
>>> Rust-dev mailing list
>>> [email protected]
>>> https://mail.mozilla.org/listinfo/rust-dev
>>
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev