rust-sizedbytes

Rust macro annotating the constant size value to a constant bytestring

The feature allows to embed a constant byte string in source code and use its byte-size during compile time to declare other buffer of specific preset size.

Example Cargo.toml ```init

[dependencies] bytestool = "0.2.0" sizedbytes = "0.1.0" ```

Example main.rs ```rust

![feature(plugin)]

![plugin(bytestool)]

[macrouse(sizedbytes)]

extern crate sizedbytes;

use sizedbytes::SizedBytes;

fn main() { const CONSTDATA : SizedBytes = sizedbytes!(b"0123456789"); // size 10, not nul-terminated // equivalant to sizedbytes!([ 48u8, 49u8, 50u8, 51u8, 52u8 53u8 54u8, 55u8, 56u8, 57u8 ]) let runtimebytes = b"0123456789";

let mut buffer : [u8; 2 * CONSTDATA.size ] = [0; 2 * CONSTDATA.size ]; for (i, charbyte) in CONSTDATA.bytes.intoiter().enumerate() { buffer[i * 2] = *charbyte; } } ```

This feature is analog to the feature in C, where the function 'sizeof' is deriving the const length of the embedded string during compile time, which can be used to initialize other buffer of specific constant size. ```C const char CONSTDATA[] = "0123456789"; // size 11, as nul-terminated /* equivalant to: char CONSTDATA[] = ['0','1','2','3','4','5','6','7','8','9', '\0'] */ const int N = sizeof(CONST_DATA) - 1;

// allocate on stack, preset during compile time char buffer[N * 2];

int i=0; for (i=0; i