配列の周りに newtype ラッパーがあります。配列のサイズを手動で渡す代わりに使用できるsize_of
と思いましたが、コンパイラは私が間違っていると考えています。
use std::mem::{size_of, size_of_val};
#[repr(C, packed)]
struct BluetoothAddress([u8, ..6]);
fn main() {
const SIZE: uint = size_of::<BluetoothAddress>();
let bytes = [0u8, ..SIZE];
println!("{} bytes", size_of_val(&bytes));
}
私はナイトリーを使用しています:rustc 0.13.0-nightly (7e43f419c 2014-11-15 13:22:24 +0000)
このコードは次のエラーで失敗します。
broken.rs:9:25: 9:29 error: expected constant integer for repeat count, found variable
broken.rs:9 let bytes = [0u8, ..SIZE];
^~~~
error: aborting due to previous error
Rust Reference on Array Expressionsは、これが機能するはずだと私に思わせます:
[expr ',' ".." expr]
フォームの の後の式は、".."
リテラルや静的アイテムなど、コンパイル時に評価できる定数式である必要があります。